PDA

View Full Version : c++ compiling



vijesh758
February 2nd, 2010, 08:33 PM
i got this message while try to compile please help me
vijesh@computer:~$ sudo gedit myprogram.cpp
vijesh@computer:~$ g++ myprogram.cpp -o myprog
myprogram.cpp:1:21: error: iostream.h: No such file or directory
myprogram.cpp:2:18: error: conio.h: No such file or directory
myprogram.cpp:3: error: ‘::main’ must return ‘int’
myprogram.cpp: In function ‘int main()’:
myprogram.cpp:6: error: ‘clrscr’ was not declared in this scope
myprogram.cpp:7: error: ‘cout’ was not declared in this scope
myprogram.cpp:8: error: ‘cin’ was not declared in this scope
myprogram.cpp:10: error: ‘getch’ was not declared in this scope

Chamillionaire2
February 2nd, 2010, 08:37 PM
Try using gcc instead.

lisati
February 2nd, 2010, 08:39 PM
Isn't gcc for C programs and g++ for C++?

Try this instead:

sudo apt-get install build-essential

smdawson
February 2nd, 2010, 08:44 PM
Could you post the code, and explain what you did? I'm new to programming and could be wrong, but it looks like you possibly did not declare a namespace, or maybe initialize your variables.

smdawson
February 2nd, 2010, 08:46 PM
...actually, listen to the other two guys. :)

nvteighen
February 2nd, 2010, 09:47 PM
g++ is for C++; gcc is for C. Both are part of GCC, the GNU Compiler Collection. I hope that clears things up.

Now, current C++ doesn't use the .h extension for standard headers any longer. Standard headers like iostream, fstream, math, etc. are referred as that, while non-standard ones are required to have .h as extension.

Also, conio.h is a C header specific for MS-DOS. In the UNIX and Unix-like world, the features you get in conio.h are part of the ncurses library, but be aware that it's a C library too and though there are C++ bindings for it, I haven't found any in the Debian/Ubuntu repositories yet... maybe I haven't searched well :P