String problem when compiling with gcc3.0.2 in an Alpha with Tru64

Michal Lipták liptak@isdd.sk
Fri Jan 24 12:47:00 GMT 2003


a question like this was asked million times here..

1.use <iostream> instead of iostream.h
2.type 'using namespace std;' somewhere in your code..
m.


-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On Behalf Of Jorge Andreu García
Sent: Friday, January 24, 2003 1:45 PM
To: gcc-help@gcc.gnu.org
Subject: String problem when compiling with gcc3.0.2 in an Alpha with Tru64


Hello.
 
Trying to compile a short "Hello World!" program I have had several problems with strings. Here is the source code:
 
#include <iostream.h>
#include <string>
//#include <bits/stringfwd.h>
 
int main ()
{
 cout << "Hola!" << endl;
 
 string pepe;
 pepe = "Hola con string";
 cout << pepe << endl;
 
 return 0;
}

Easy, isn't it? Yhis is what gcc tells me:
 
bash-2.02$ g++302 hello.cpp -o hello.exe 
hello.cpp: In function `int main()':
hello.cpp:8: `string' undeclared (first use this function)
hello.cpp:8: (Each undeclared identifier is reported only once for each 
   function it appears in.)
hello.cpp:8: parse error before `;' token
hello.cpp:9: `pepe' undeclared (first use this function)

Can somebody help me? I have tried including "bits/stringfwd.h" (where I have found a typedef defining string) but still have the same problem. Somewhere in this mailing list I have read about putting std::string and it seems to work, but the problem is I have to migrate a lot of source files from Linux(Mandrake) where previous program works to Tru64 machine and there are lots of string defined and change all is goiung to be a lot of work, so I hope another way to do this can be possible.
 
Thnaks in advance:
 
Jorge Andreu



More information about the Gcc-help mailing list