LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem in compiling c++ prg's (https://www.linuxquestions.org/questions/programming-9/problem-in-compiling-c-prgs-770162/)

sach1n 11-19-2009 03:57 AM

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

Komakino 11-19-2009 04:03 AM

Have you remembered to #include <iostream> and included the line 'using namespace std;'?

e.g:
Code:

#include <iostream>

using namespace std;

void main(int argc, char** argv){
 cout << "Hello world" << endl;
}


Also make sure you're calling g++ to compile it. gcc is the C compiler, not the C++ compiler.

escaflown 11-19-2009 07:45 AM

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:

Originally Posted by sach1n (Post 3762404)
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


Alien Bob 11-19-2009 08:48 AM

I fail to see how this is a Slackware issue. Can this thread be moved to the programming forum?

Eric

Komakino 11-19-2009 08:53 AM

Quote:

Originally Posted by Alien Bob (Post 3762707)
I fail to see how this is a Slackware issue. Can this thread be moved to the programming forum?

Eric

I believe the OP thought his issue was related to not having the correct slack packages installed, but you're right in that this isn't a Slackware specific issue and should probably be moved.

XavierP 11-19-2009 09:26 AM

In light of the above, moved to Programming

smeezekitty 11-19-2009 11:50 AM

have you included iostream? or iostream.h if using the old standard?

sach1n 11-20-2009 11:46 PM

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

ta0kira 11-21-2009 12:41 AM

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.