Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

compiling with string.h in C++

I'm having trouble loading the "string" class into my C++ files. I compile using gcc through Terminal. In my main program file, I have
#include <string.h>
at the top, but when I compile (by typing "make" into the command line), the line
string s;
gets the error
'string' undeclared

If I type
using namespace standard;
below the #include and compile, I get the error
parse error before "namespace"

Do you have any suggestions for how I can get string library working? Do I need to add a line to the makefile?

PowerBook G4, Mac OS X (10.3.9)

Posted on Jun 28, 2006 3:09 PM

Reply
Question marked as Best reply

Posted on Jun 28, 2006 4:58 PM

1. You probably mean "using namespace std", not "standard".
2. You probably want <string>, not <string.h> - the two are not equivalent.
3. The file has a .cpp or .c++ extension, right? If it doesn't, it'll try to compile it as C, which doesn't have namespaces.
2 replies

Jun 29, 2006 12:41 PM in response to andfarm

Thanks for your quick reply. I was mistaken - I thought I had been compiling in C++ all along, but I was actually compiling in C. Naturally, when I found and attempted to compile examples using the string class in C++ (e.g. "using namespace" and declaring strings using "string" instead of "char*"), they didn't compile correctly in C.

compiling with string.h in C++

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.