Archived

This topic is now archived and is closed to further replies.

Eric

C++ string class

Recommended Posts

Apparently there is a standard C++ "string" class, but my MSVC compiler refuses to acknowledge it... test.cpp: #include <string> string blah; Compiling this gives me error C2146: syntax error : missing ';' before identifier 'blah' error C2501: 'string' : missing storage-class or type specifiers I've found string's definition in the file "xstring": typedef basic_string < char, char_traits < char >, allocator < char > > string; I assume that including "string" in my test file is supposed to somehow also include xstring, thereby giving me string's definition. Also, ya know that type information that pops up while you're typing in MSVC? It knows that blah is a string, and it knows what a string is. But still my test file won't compile. Any ideas? Edited by - Eric on February 17, 2002 9:21:42 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
std::string blah;

or

using namespace std;
string blah;

Share this post


Link to post
Share on other sites
Two longshots:

  • Incorrectly set-up include file directories

  • Wrong namespace. Be sure to "using namespace std;"



I doubt either of those are correct. I don''t mean to insult your intelligence by suggesting them

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

Share this post


Link to post
Share on other sites
That string class is part of the STL (Standard Template Libarary). All members of the STL are wrapped in the namespace std, so you need either to qualify any references or use using
  
#include <string>
std::string mystring;

...or...
  
#include <string>
using namespace std;
string mystring;

Share this post


Link to post
Share on other sites