Computing.Net > Forums > Programming > Where are cout & cin?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Where are cout & cin?

Reply to Message Icon

Name: matsuzay
Date: October 29, 2002 at 22:36:30 Pacific
OS: Linux
CPU/Ram: 568M/128M
Comment:

Hi,
I have just switched my programming platform from Win9X to Linux. First, I wrote a simple test program (T1.cpp)

#include

int main(int, char**)
{
cout succeeds (T1.o is created)
$ gcc -o T1 T1.o
Then, I got the error messages
1.undefined reference to cout
2.undefined reference to 'ostream::operator<<(char const*)'

Looks like the compiler (I am using GNU C++ compiler ver.2.95.3) did not find the libraries for stream classes. Where are they? As I searched the web, it looks like I need glib++ but I wasn't able to find it either on my PC or on the web.
Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: matsuzay
Date: October 29, 2002 at 22:47:19 Pacific
Reply:

I noticed that part of my previous message was lost. The program is as follows:

#include int main(int, char**)
{
cout << "Test program\n";
return 0;
}

compilation:

$ gcc -c T1.cpp
This succeeds (T1.o is created)

$ gcc -o T1 T1.o
Fails (error messages are as above)


0

Response Number 2
Name: Gauthier
Date: October 30, 2002 at 01:36:47 Pacific
Reply:

Hi!

it still did not display right. You can use the code converter that you can download from the main "programming" forum page, in order to display nicer code.

So I don't now which header you were trying to include.
You're supposed to include iostream.h.

you could have gone to google, and typed "cout header file #include" in the search box. It would have led you to iostream.h

Now if you WERE using iostream.h, I think I cannot be of great help. You should try to include "iostream" (*without* the ".h"). I heard some people speaking about that.

- Hope it helps -


0

Response Number 3
Name: Gauthier
Date: October 30, 2002 at 01:42:50 Pacific
Reply:

Well, sorry.

It might be, as you seem to think, a problem with making the compiler aware of your libraries.

But shouldnt it then send an compiler error "cannot open include file", or something?

If not, I don't know. Sorry


0

Response Number 4
Name: Marcus
Date: October 30, 2002 at 04:48:29 Pacific
Reply:

Hi!

Looks like you are mixing a bit of c and c++.

Try using std::cin or just add "using namespace std" to the top of your program.

/Marcus


0

Response Number 5
Name: mm_freak
Date: October 30, 2002 at 09:08:43 Pacific
Reply:

What about including iostream.h ?

#include

int main() {
cout << "foo" << "bar" << endl;
return 0;
}

If it compiles, but doesn't link, you should check, if you have and are using all libraries needed. I dunno, which of them you need under Linux, but on most distributions this should link well.


0

Related Posts

See More



Response Number 6
Name: matsuzay
Date: October 30, 2002 at 16:52:25 Pacific
Reply:

Thanks for your replies. And Gauthier, thanks again for letting me know of the coder.exe. I hope my code will appear properly this time.
I am including iostream.h in my sample program.

#include <iostream.h>

int main(int, char**)
{
    cout << "Test program\n";
    return 0;
}

After reading your replies, I have tried the followings:
1. adding "using namespace std" at the beginning of the program
2. using std::cout instead of cout
3. replacing iostream.h with iostream
None worked. The linker still returns the error message "undefined reference".

Looks like I do not have the class library. If anyone can compile C++ codes which use stream classes in Linux, I would like to know what version of gcc s/he is using, and if s/he has glib++ and where s/he has gotten it. Thanks in advnce,


0

Response Number 7
Name: matsuzay
Date: October 30, 2002 at 17:58:12 Pacific
Reply:

Hi all,

It turned out to be a very simple mistake. I should have used g++ instead of gcc. I got the clue from http://ricardo.ecn.wfu.edu/glib-linux-archive/0006/0031.html.

Thanks again for all your help!!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Where are cout & cin?

Where are the command files hidden? www.computing.net/answers/programming/where-are-the-command-files-hidden/17668.html

Need Help with Structures www.computing.net/answers/programming/need-help-with-structures/15705.html

C++ Application StartUp www.computing.net/answers/programming/c-application-startup-/4662.html