Problem in compiling c++ prg's
Hey Slacker pls help me !
I've installed Slackware 13[DVD-whole setup] which include gcc-base and gcc-g++ but I've problem compiling even a simple "Hello world" prg in g++. It show the error msg: error in function main(): 'cout' was not declared in the scope 'endl' was not declared in the scope The gcc (.c) files are fine I've tried installing the whole pkgs of 'gcc' many times even the OS but it's not helping I want help in urgent uname -a: ---> linux-2.29.x-smp AMD Athlon 64x2 Dual core |
Have you remembered to #include <iostream> and included the line 'using namespace std;'?
e.g: Code:
#include <iostream> Also make sure you're calling g++ to compile it. gcc is the C compiler, not the C++ compiler. |
It's simply a programming error. Like Komakino said it, you probably didn't use the iostream library or the std namespace. In C++, cout and endl are defined in the std namespace (using namespace std; ) and you also need to include iostream library ( #include <iostream>). You can find a good C++ tutorial at http://www.learncpp.com/
Quote:
|
I fail to see how this is a Slackware issue. Can this thread be moved to the programming forum?
Eric |
Quote:
|
In light of the above, moved to Programming
|
have you included iostream? or iostream.h if using the old standard?
|
As escaflown said that this is a simple programming issue, but I've never got this kind of problem on my Linux Mint.
What will be the reason for this ?? Any way's thanks Komakino for such a fast reply :) Thank you all |
A compiler that doesn't implement the C++ standard correctly would be my guess (on your other installation.)
Kevin Barry edit: That is to say: If this exact code compiled on LM, it's probably a non-standard compiler. Otherwise, I'd guess you're mistaken. |
All times are GMT -5. The time now is 06:18 PM. |