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 ...
- 08-19-2008 #1Just 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?
- 08-19-2008 #2
Um fix them and recompile?
Or give us more information the code + errors would be a good startIf 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.
- 08-19-2008 #3Registered Linux user #270181
TechieMoe's Tech Rants
- 08-19-2008 #4Just 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
- 08-19-2008 #5
Don't use "gcc" to compile, for C++ you must use "g++" instead.
Correct syntax would be:
The -o parameter just tells the compiler to output the result to a filename you specify instead of a.out.Code:g++ b.cpp -o filename
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:
And the code compiles with the command:Code:#include<iostream> using namespace std; int main() { int x; cout << "Please enter a number: " << endl; cin >> x; cout << x+1 << endl; return 0; }
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?".Code:g++ b.cpp -o b
Last edited by gruven; 08-19-2008 at 06:09 PM. Reason: advice
- 08-20-2008 #6Just 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.
- 08-20-2008 #7
- 08-20-2008 #8Just 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
- 08-20-2008 #9
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


Reply With Quote
