C++ compilation problem in Ubuntu
After i create a file with text editor, when i use the compile command
gcc filename.cpp fatal error - iostream.h: No such file or directory compilation terminated. And when i try gcc -o filename.cpp it says gcc: no input files. Please Help me. |
For C++ programs, you use g++, rather than gcc (so that the standard C++ library is linked automatically). Also, you should be using "iostream", rather than "iostream.h". The latter is the older form of the header and it probably doesn't exist on your system (it certainly doesn't on mine).
Also, the -o flag is used to specify the name of the executable, so you're not actually giving a source file to be compiled, hence the error message in the second case. |
Sir, my example file is ---
gedit name.cpp #include<iostream> int main() { cout<<"I hope this works"; } When i am compiling with command g++ name.cpp it gives 2 messages-- 1. In function 'int main()' 2. error - 'cout' not declared in this scope. |
Ah yes. You also need the line "using namespace std;" after the #include, because cout, endl and friends are in the namespace called "std" (which you'll learn about later if you get that far!).
Edit: Also, in future, please post code between [code] tags to preserve indentation. |
Thank U sir, after over a year of C programming, i was into C++ classes for over a week. i had covered much but inability to compile and test some programs was irritating. But thank U again sir, i have compiled my first C++ program. I will always be grateful to U. :) :) :)
Regards, Soumya Ranjan (India) |
Please mark your thread as solved by using the "Thread Tools" at the top. Also, please write words out in full here.
|
All times are GMT -5. The time now is 03:57 PM. |