Click to See Complete Forum and Search --> : g++ / IOStream? / Suse 8.1
chris1480
04-26-2003, 05:23 AM
Hi,
I've got a somewhat strange problem. I updated my version of Suse to 8.1 recently and since then I'm not able to include the IOSTREAM header file anymore.
Even a simple hello world program complains that it doesn't know what COUT is.
I've also searched for the iostream file on my disk and the location is /usr/include/g++. I assume that's where it must be.
Under yast2 the C++ library libstd... is also installed.
Does anyone have an idea what's going wrong?
Thanks,
Chris
bwkaz
04-26-2003, 09:14 AM
Add a using std::cout; line right after where you #include <iostream>. Alternately, you can replace every instance of "cout" with "std::cout", but that's a lot of work.
If you get undefined symbol errors with endl, for example, then add using std::endl; also.
tecknophreak
04-26-2003, 10:14 AM
No, no, just use using namespace std; :D
Just messing with ya bwkaz.
bwkaz
04-26-2003, 02:29 PM
GAAH!
:D
chris1480
04-26-2003, 04:12 PM
Hi folks,
thanks for the tips, but unfortunately the error does not disappear. I've added the namespace stuff right after the #include command, under the #include command, but neither way it works :-(
Here's the program and the error message, if that's helping you to figure out the problem. To my opinion there isn't a whole lot one can do wrong.
#include <iostream> using namespace std;
int main () {
cout << "hello";
return 0;
}
$ g++ test.cc -o test
test.cc:1:21: warning: extra tokens at end of #include directive
test.cc: In function `int main()':
test.cc:6: `cout' undeclared (first use this function)
test.cc:6: (Each undeclared identifier is reported only once for each function it appears in.)
test.cc:10:2: warning: no newline at end of file
Besides, the same problem also appears in Mandrake 9.1, so I guess that it isn't a problem of the distribution, but rather a problem of the C/C++ compiler. Have they made any changes to the version 3 compiler?
Thanks again,
Chris
tecknophreak
04-26-2003, 04:59 PM
Try this...
#include <iostream>
using namespace std;
int main () {
cout << "hello";
return 0;
}
chris1480
04-26-2003, 06:30 PM
OK, it's working now.
I don't know why Mandrake still makes problems (it's not that important), but after wiping Suse and re-installing it, it suddenly works.
I have absolutely no idea what caused it.
I'd also tried your version before tecknophreak, but somehow the compiler still complained. After the re-install and with the namespace stuff it works perfectly now.
@all: Thanks for your help. I assume we can close that X-file now ;-)
Chris