Find the answer to your Linux question:
Results 1 to 9 of 9
Hi I am new to linux and I just installed fedora 8 from a dvd got along with LFY magazine. I have to compile C++ programmes for my studies. But ...
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    6

    compiling C++ programmes

    Hi
    I am new to linux and I just installed fedora 8 from a dvd got along with LFY magazine. I have to compile C++ programmes for my studies. But when I give cin, cout commands in programme it gives out errors. What I can i do now?

  2. #2
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,300
    Um fix them and recompile?

    Or give us more information the code + errors would be a good start
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

  3. #3
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by benjose View Post
    Hi
    I am new to linux and I just installed fedora 8 from a dvd got along with LFY magazine. I have to compile C++ programmes for my studies. But when I give cin, cout commands in programme it gives out errors. What I can i do now?
    We can't really help you without the source code and the specific error. Off the top of my head, if your error mentions CIN, did you forget to add using namespace std; at the top of your source file right after your imports? It's a common mistake.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  4. #4
    Just Joined!
    Join Date
    Jul 2008
    Posts
    6

    details

    I tried the follwing simple programme also
    #include<iostream>
    using namespace std;
    int main()
    {
    int x;
    cin>>x;
    cout<<x+1;
    return 0;
    }
    save this programme as b.cpp
    compiled using the command gcc b.cpp
    then I got some 10 to 12 lines as error description of which i understood nothing it go like... static_initialization_and_destruction_o(int,int)
    undefined reference to "std::ios_base::Init::init()
    undefined reference to "std::cin
    undefined reference to"std::basic_stream<char,
    undefined reference to "std::char_trais<char>>::oprator>>(init&)
    ......
    .......
    collect2:ld returned 1 exit status

  5. #5
    Linux User gruven's Avatar
    Join Date
    Dec 2004
    Location
    Arkansas
    Posts
    481
    Quote Originally Posted by benjose View Post
    I tried the follwing simple programme also
    #include<iostream>
    using namespace std;
    int main()
    {
    int x;
    cin>>x;
    cout<<x+1;
    return 0;
    }
    save this programme as b.cpp
    compiled using the command gcc b.cpp
    then I got some 10 to 12 lines as error description of which i understood nothing it go like... static_initialization_and_destruction_o(int,int)
    undefined reference to "std::ios_base::Init::init()
    undefined reference to "std::cin
    undefined reference to"std::basic_stream<char,
    undefined reference to "std::char_trais<char>>::oprator>>(init&)
    ......
    .......
    collect2:ld returned 1 exit status
    Don't use "gcc" to compile, for C++ you must use "g++" instead.

    Correct syntax would be:
    Code:
    g++ b.cpp -o filename
    The -o parameter just tells the compiler to output the result to a filename you specify instead of a.out.

    Also, to make your program make more sense, you will want to tell someone that they need to enter a number (and I also made it a bit more readable), such as:
    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
      int x;
      cout << "Please enter a number: " << endl;
      cin >> x;
      cout << x+1 << endl;
    
      return 0;
    }
    And the code compiles with the command:
    Code:
    g++ b.cpp -o b
    Also, if this is for your homework assignment, I didn't mind helping if only to get your spacing (and readability of your programs) better. No one wants to read a jumbled mess if it is open source, so please format your programs somehow that helps with readability. That is one thing I hate, looking at source and saying, WTF? Also, it will help you more if you have to look back at it, you won't have to go "WTF?".
    Last edited by gruven; 08-19-2008 at 06:09 PM. Reason: advice

    Linux User #376741
    Preferred Linux Distro: Funtoo
    There is no need to login to the GUI as root!

  6. #6
    Just Joined!
    Join Date
    Jul 2008
    Posts
    6

    Thank you Gruven

    Thank you very much Gruven
    That was not any home work. I got a linux dvd only few days ago and just started learning linux installing it by meself in my harddisk with the help of books and downloaded tutorials .I am interested in the idea of Open Source system. I am a Physics Student and I believe science belongs to all not to some body only.

  7. #7
    Linux User gruven's Avatar
    Join Date
    Dec 2004
    Location
    Arkansas
    Posts
    481
    Quote Originally Posted by benjose View Post
    Thank you very much Gruven
    That was not any home work. I got a linux dvd only few days ago and just started learning linux installing it by meself in my harddisk with the help of books and downloaded tutorials .I am interested in the idea of Open Source system. I am a Physics Student and I believe science belongs to all not to some body only.
    I agree, and was only covering my bases. I am learning C++ myself and I feel that any help is good help.

    Please don't hesitate to post any more questions, and I am sure someone around here will know!

    Linux User #376741
    Preferred Linux Distro: Funtoo
    There is no need to login to the GUI as root!

  8. #8
    Just Joined!
    Join Date
    Aug 2008
    Posts
    4
    Hi guys, I am a new Linux user. I use Redheat 4.
    Can you recommend me a link or a book that can explain me the principle of FORK in linux.

    Thanks a lot

  9. #9
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by imelnik View Post
    Hi guys, I am a new Linux user. I use Redheat 4.
    Can you recommend me a link or a book that can explain me the principle of FORK in linux.

    Thanks a lot
    I'm a fan of WROX programming books:

    Open Source: Beginning Linux*Programming, 3rd Edition - Book Information and Code Download - Wrox

    For my Operating Systems class in college we made lots of command-line Linux applications, including things that dealt with forking. The book linked above was our text for the class.
    Registered Linux user #270181
    TechieMoe's Tech Rants

Posting Permissions

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