![]() |
|
#1
|
|||
|
|||
C++ beginnerDear All
I am a beginner to learn C++. I am following an on-line tutorial. When I try the first C++ program as described in the tutorial (which is supposed to work without any problem, as it is said in the tutorial), I got many error message. The folllowing is the program (I name it as test.cpp: CPP / C++ / C Code:
I am using Suse 10.0 linux and the gcc compiler installed by Suse 10.0. After I gcc the programm above ( gcc test.cpp ) I got the error message. When I try to correct the error, and re-compile it, I got other error message! Can some one point out what mistake I made? Or can you kindly supply me a workable, small program that will run under gcc compiler? I just want to get a rough idea about how C++ works. Last edited by admin II : 11-Nov-2006 at 04:17.
Reason: fixed broken [cpp] ... [/cpp] tag
|
|
#2
|
||||
|
||||
Re: C++ beginnerTry this code with g++ test.cpp
CPP / C++ / C Code:
__________________
Gravitation is not responsible for people falling in love. -Albert Einstein Last edited by admin II : 11-Nov-2006 at 04:17.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#3
|
||||
|
||||
Re: C++ beginnerCPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: C++ beginnerAlso, iostream.h is deprecated. Use <iostream> and put
CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: C++ beginnerThanks for all your kindly help. I tried all the suggestion, here is what I got:
#include <iostream> int main(); { std:: cout << "Hello World!\n"; return 0; } After I g++ above, the following error message appear: test.cpp:3: error: expected unqualified-id before ‘{’ token Next I delete the semicolon for line 2 (int main() #include <iostream> int main() { std:: cout << "Hello World!\n"; return 0; } After I g++ again, I got the file a.out (what should I do next?); But If I use gcc, I got many error message (see following): doudou66@linux:~/C++> gcc test.cpp /tmp/ccvWewmo.o: In function `main': test.cpp test.cpp /tmp/ccvWewmo.o: In function `__tcf_0': test.cpp /tmp/ccvWewmo.o: In function `__static_initialization_and_destruction_0(int, int)': test.cpp /tmp/ccvWewmo.o collect2: ld returned 1 exit status The next thing I did is to add using namespace std, so the program became: #include <iostream> using namespace std; int main() { std:: cout << "Hello World!\n"; return 0; } After I g++, I got the file a.out. But If I try to gcc, I still got the many error message. What's the difference between g++ and gcc? If I assume g++ works in my case (as I can get the file a.out), what should I do next? To link? But how? It didn't specify in the tutorial? Or is it possible I didn't set the gcc correct? (I just install the gcc and use it right away, didn't do anything else). |
|
#6
|
|||
|
|||
Re: C++ beginnerQuote:
Enter ./a.out on the command line. Many (most?) distributions these days to not include the current directory on the PATH (it's a security issue). So you have to enter the "dot" to indicate current directory. Quote:
gcc and g++ are both part of the GNU compiler suite. To put it in simplest terms, if you have a C source file called "something.c" then you can compile it with the following: gcc something.c If there are no errors, then the default output file name (the executable) is called a.out. There are command-line switches that you can use to cause other things to happen, but this is the simplest. If you have a C++ source file called "something.cpp" then you can compile it with the following: g++ something.cpp f there are no errors, then the default output file name (the executable) is called a.out. There are command-line switches that you can use to cause other things to happen, but this is the simplest. Regards, Dave |
|
#7
|
|||
|
|||
Re: C++ beginnerQuote:
gcc is the C compiler invocation method. g++ is the C++ compiler invocation method. Use: g++ -g -Wall -W -o executabe-name-that-you-want-to-use your-cpp-file.cpp -g means to include debugging symbols in the build. These will be necessary when debugging your applications. Use gdb in order to debug your applications. -Wall means to include all warnings. -W means to include "extra" warnings. It has been replaced by -Wextra, but the "old" version -W is still supported. -o filename means to output the result of compilation and linkage to the named filename. If not specified, a.out is used. :davis: |
|
#8
|
|||
|
|||
Re: C++ beginnerThank you SO MUCH for the excellent guidance. I hope I can learn more from you in the future.
|
Recent GIDBlog
2nd Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pointer Usage in C++: Beginner to Advanced | varunhome | CPP / C++ Forum | 0 | 19-Aug-2005 09:25 |
| Suggestions for beginner | Propain | CPP / C++ Forum | 1 | 16-Mar-2005 20:46 |
| RAID 0 -- beginner questions, need recommendation | ldriskell | Computer Hardware Forum | 2 | 09-Jul-2004 19:47 |
| Apache 1.3.28 >XP > Complete Beginner setting alias? | thinnk | Apache Web Server Forum | 2 | 26-Mar-2004 00:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The