Where are strings?

Post: #1
I can include all 3 of the following headers:

#include <string>
#include <string.h>
#include <cstring>

Yet declarations of

String j;


string j;

both get rejected by the compiler, stating that, "string is used as a type, but is not defined as a type." when in a class, and "string undeclared (first use this function)" elsewhere. I'm using Xcode 1.2 (OSX 10.3.9). What should I do?
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
#include <string>

std::string s;

Also possible:

#include <string>
using std::string;

string s;

Also possible, but not recommended:

#include <string>
using namespace std;

string s;
Quote this message in a reply
Posts: 834
Joined: 2002.09
Post: #3
To clarify: all of the STL is in the std:: namespace. Hence, you have to specify that you want std::string (which is the proper name) in any of the three ways mentioned above. Some compilers pull in the std:: namespace silently, but it's wrong and dangerous. Ninja
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  generate MD5 strings with Objective-C? fernandovalente 3 4,076 Jan 27, 2010 09:29 AM
Last Post: Hog
  C strings mikey 24 8,121 May 18, 2009 04:52 AM
Last Post: Oddity007
  Converting integer/numeric values to Strings vnvrymdreglage 5 3,466 Oct 23, 2006 07:18 PM
Last Post: vnvrymdreglage
  Converting strings to functions Joseph Duchesne 10 5,237 Feb 23, 2005 11:42 PM
Last Post: Skorche