bgriscom
asked on
Can't seem to implement the string header properly
Hi,
I'm using C++ on Red Had Linux 8.0. I'm using g++ to compile my programs. I've properly inserted the <iostream> header, but it seems that the others I try do not work correctly.
For instance, I've been trying to use <string> and <fstream> but both give me errors. When I use #include <string> and then implement the string code in my program, such as string x = "test"; I receive the following error:
block_good.cc: In function `int main()':
block_good.cc:58: `string' undeclared (first use this function)
block_good.cc:58: (Each undeclared identifier is reported only once for each
function it appears in.)
block_good.cc:58: parse error before `=' token
Any help would be great.
Thanks!
I'm using C++ on Red Had Linux 8.0. I'm using g++ to compile my programs. I've properly inserted the <iostream> header, but it seems that the others I try do not work correctly.
For instance, I've been trying to use <string> and <fstream> but both give me errors. When I use #include <string> and then implement the string code in my program, such as string x = "test"; I receive the following error:
block_good.cc: In function `int main()':
block_good.cc:58: `string' undeclared (first use this function)
block_good.cc:58: (Each undeclared identifier is reported only once for each
function it appears in.)
block_good.cc:58: parse error before `=' token
Any help would be great.
Thanks!
ASKER
I tried changing it to string.h. No dice.
ASKER
I tried changing it to string.h. No dice.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is the file string.h and filestream.h in the correct directory on the machine?
mlmcc
mlmcc
ASKER
Using the #include <string> and "using std::string" fixes the problem!
I don't understand why I didn't have to do this in my computer science courses. Do I need to modify a header file to include this automatically?
Thanks for the assistance.
Did you happen to use MS VC++? If so it can be setup to not requie the std:
gnu I believe requires it. There is a way around it but I forget what it is.
SOmething like
Using <String.h>
mlmcc
gnu I believe requires it. There is a way around it but I forget what it is.
SOmething like
Using <String.h>
mlmcc
ASKER
Thanks to everyone for the help. If you have any ideas as to why I never had to include this before or if it was built into my header file, please let me know.
Thanks.
Thanks to mlmcc and JZ4096 for the assistance.
Thanks.
Thanks to mlmcc and JZ4096 for the assistance.
Including <string.h> does not include C++'s new STL string class, but only C's string manipulation functions (strcat, strlen, strcmp, etc).
Including <string> includes the STL string, but it is in namespace std by default. To bring it into the global namespace, using namespace std; or using std::string; is necessary.
~JZ4096
Including <string> includes the STL string, but it is in namespace std by default. To bring it into the global namespace, using namespace std; or using std::string; is necessary.
~JZ4096
#include <string.h>
mlmcc