C++ string class

Started by
7 comments, last by Eric 22 years, 2 months ago
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
Advertisement
std::string blah;

or

using namespace std;
string blah;

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.]

[twitter]warrenm[/twitter]

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;  
AP apparently has less faith in you than I do. That sounds like the most likely source of the problem.

Later,
ZE.

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

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

[twitter]warrenm[/twitter]

quote:Original post by Anonymous Poster
std::string blah;

or

using namespace std;
string blah;

or

using std::string;
string blah;

Just to be complete.

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
Sounds like we''ve got it covered.

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

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

[twitter]warrenm[/twitter]

Good Lord! What took you guys so long? I''ve been waiting for nearly 9 minutes!
Hey whipper-snapper, we don''t exist to serve you; we just happen to have no lives

Later,
ZE.

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

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

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement