Where are strings?

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

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

Yet declarations of

Code:
String j;

and

Code:
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
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Code:
#include <string>

std::string s;

Also possible:

Code:
#include <string>
using std::string;

string s;

Also possible, but not recommended:

Code:
#include <string>
using namespace std;

string s;
Quote this message in a reply
Oldtimer
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,344 Jan 27, 2010 09:29 AM
Last Post: Hog
  C strings mikey 24 8,639 May 18, 2009 04:52 AM
Last Post: Oddity007
  Converting integer/numeric values to Strings vnvrymdreglage 5 3,655 Oct 23, 2006 07:18 PM
Last Post: vnvrymdreglage
  Converting strings to functions Joseph Duchesne 10 5,511 Feb 23, 2005 11:42 PM
Last Post: Skorche