Find the answer to your Linux question:
Results 1 to 8 of 8
iam new to linux, but i have used c++ in dos platform. wht are the differences in using C++ in linux and how do i go about it. need all ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2003
    Location
    India
    Posts
    20

    linux newbie


    iam new to linux, but i have used c++ in dos platform.
    wht are the differences in using C++ in linux and how do i go about it.
    need all the helpi can get

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    It's basically the same, since C and C++ are standardized. If you've used DJGPP to compile for DOS, you'll find it extremely similar. There are of course some platform dependent calls, but I don't think that you've used them anyway.
    Just write a program with your favorite editor (I recommend emacs), and compile it with "c++ file.cpp", and it will produce the file a.out, which you can run. Remember that the Linux shell, unlike the DOS shell, won't run binaries in the current directory by default, only the directories in the PATH variable (whereas command.com runs binaries in the directories specified in PATH _and_ the current directory), so you'll need to run "./a.out".

  3. #3
    Just Joined!
    Join Date
    Mar 2003
    Location
    India
    Posts
    20
    thanks for replying
    i have heard of DGJPP but have never used is it, could you tell me more about it.
    Also is there any change in the syntax of the program, while writing in CPP in linux.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    There is absolutely no change in syntax. Like I said, C and C++ are standardized.
    DJGPP is just the DOS port of gcc and glibc; I don't really know what more to say about it, except it's pretty good.

  6. #5
    Just Joined!
    Join Date
    Mar 2003
    Location
    India
    Posts
    20
    HI
    I wrote a program just as u told me to. on EMACS
    #include<iostream.h>
    void main()
    {
    cout<<"hello,World";
    }

    saved it as hello.cpp and then compiled it bygcc hello.cpp
    it showed an error "this file containes atleast one deprecated or antiquated header........Consider replacing <x.h> with<x>.
    So I did;I changed iostream.h with <iostream> and compiled it again and the following errors showed

    1.main must return int in function int main(...)
    2.cout undeclared

    I am completely confused.
    could u give me step by step instructions as to compiling and running.Also, I noticed that the quotes characters " & ' will only be displayed on thescreen after hitting the spacebar key. Is there any way to change this.

    Thanks for all the help

  7. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    What is bygcc? I'm pretty sure the program you should be use either c++ or g++ (as in GNU C++).
    Also, it's supposed to be int main(int argc, char **argv), not void main(void). Windows and DOS accepts void main(void), but this is UNIX. You can use int main(void) if you want, but then you won't get the command line arguments.

  8. #7
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The reason that the quote characters won't display is probably because you're using a keyboard layout with some extra dead keys. For example, if you try pressing " and then a, you'll probably get ä. The only way to change that is to change your keyboard layout.

  9. #8
    Just Joined!
    Join Date
    Aug 2002
    Location
    New Jersey
    Posts
    28
    The reason for error number 2 (cout undeclared) can be frustrating for programmers used to C++ from a few years back. In the latest restandardization of C++, standard objects (cout, cin, endl, string, etc.) are now a part of the namespace std. So, whenever you plan on using these objects, you need to do one of the following before you actually use them.

    //include files

    using namespace std;

    //rest of program

    OR

    //include files

    using std::cout;
    using std::cin;
    using std::endl;
    //etc

    //rest of program.

    the first one gives you access to the entire namespace, the second gives you access to only individual the objects you want in that namespace.

    Note: you can do this without "using" anything. You just have to put std:: before each object name when it is actually used.
    i.e.
    cout << "Hello World" << endl;

    would become

    std::cout << "Hello World" << std::endl;

    Hope this clears any confusion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •