   STL string's c_str ( ) method isn't working correctly, help!
  I''m having a very strange problem.  My STL strings are not behaving as they did when compiled in Visual Studio 6.0.  I am now trying it on .NET and I''m getting a strange problem.string test = "test";printf ("testing : %c%c%c%c\n", test[0], test[1], test[2], test[3]);printf ("testing : %c%c%c%c\n", test.c_str()[0], test.c_str()[1], test.c_str()[2], test.c_str()[3]);printf ("testing : %s", test.c_str());The output comes out as:test<4 characters of gibberish>< a lot of gibberish>Strangely I have tried this in a "new" environment and it works normally, but when I use it in my game code it screws up.  I''m not sure what the problem is, because it was working just fine before I tried compiling in .NET .  My declarations seem fine, I use#include <string>using namespace std;as I''m supposed to, and the compiler doesn''t complain.  Any thoughts? 
  Did you make clean before you built in the upgraded compiler? Else old crufty compiled code may still be in the .obj files.Also, make sure you link against the same msvcprt lib that your headers assume -- you can''t mix/match between compiler versions. This is likely your problem. ;  Yes, cleaning it fixed the problem.  Stupid me, I didn''t even think about that.  Thanks a lot! ;  std::string is not part of the STL  Looking for a serious game project?www.xgameproject.com;quote:Original post by Max_Payne  std::string is not part of the STL  Err, std::string is   part of STL.Did you know that std::string is just a typedef to thestd:basic_string template?   Kami no Itte ga ore ni zettai naru! ;quote:Original post by tangentz  quote:Original post by Max_Payne   std::string is not part of the STL  Err, std::string is    part of STL.Did you know that std::string is just a typedef to thestd:basic_string template?   Er... nope. Part of the STL is in the C++ Standard Library. Also std::string is in the C++ Standard Library. It was written to conform to the STL iterator concept. However, it is not part of the STL.;quote:Original post by petewood   Er... nope. Part of the STL is in the C++ Standard Library. Also std::string is in the C++ Standard Library. It was written to conform to the STL iterator concept. However, it is not part of the STL.OK, where in the Standard says it's not?  I'd like to see it.Also, why would Scott Meyers talk about string in Effective STL,if it's not in the STL?And then there is the SGI STL reference which includes basic_string, among other things.I know that some stuff in there didn't make it into the C++Standard in 1998 (hash_map, slist, rope...etc).I'm not saying I'm right.  I'm just stating something thatseems inconsistent.  And, I'd be glad to be corrected.   [Edit]: link to SGI STL referenceKami no Itte ga ore ni zettai naru!   [edited by - tangentz on February 2, 2004 11:18:51 AM];  I thought the C++ Standard Library was the old C library and STL combined (which would make std::string a part of STL) ;quote:Original post by tangentzOK, where in the Standard says it's not?  I'd like to see it.Also, why would Scott Meyers talk about string in Effective STL,if it's not in the STL?And then there is the SGI STL reference which includes basic_string, among other things.I know that some stuff in there didn't make it into the C++Standard in 1998 (hash_map, slist, rope...etc).I'm not saying I'm right.  I'm just stating something thatseems inconsistent.  And, I'd be glad to be corrected.   [Edit]: link to SGI STL referenceKami no Itte ga ore ni zettai naru!   [edited by - tangentz on February 2, 2004 11:18:51 AM]The original STL came from Hewlett-Packard, before it was incorporated into the 98 standard.  std::basic_string was not in HP's STL.http://www.hpl.hp.com/techreports/95/HPL-95-11.htmlThe standard doesnt mention 'STL' at all.    [edited by - Jingo on February 2, 2004 11:40:56 AM];  if your just trying to get 1 char.. do this!! you don't need .c_str() ... just use .c_str when you want to print out the or convert the full string.. // All you need for simple chars   printf ("testing : %c%c%c%c\n", test[0], test[1], test[2],test[3]);//this is pretty pointless to do.. look abovetest.c_str()[0], //and this is for the full string.. :)test.c_str()   [edited by - tonic151 on February 3, 2004 11:00:16 AM]