#include <iostream>
#include <string>
using namespace std;
string GetStr()
{
return string("Hello");
}
int main(int argc, char *argv[])
{
const char* p = GetStr().c_str();
cout << p << endl;
cin.get();
}
============================
Run the code above, Dev C++ will normally output the string "Hello",
however, VS 2005 should output an empty string!
In my opinion, string class is vital to almost every C++ program, and
VS 2005 as a C++ compiler is widely used by programmers, if string
class is wrongly implemented by Microsoft, that will be a disaster!
Because GetStr() returns a temporary object, so the object will be
deleted after the function returns.
I'm very sorry for my misunderstanding.
I don't know how well STL works with Unicode, but this code won't port to Unicode.
Note that for MFC programming, CString is a much better choice than string.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joe:
If you do
typedef std::basic_string<TCHAR> tstring;
then STL handles Unicode just fine. And it doesn't have dangerous
conversion constructors like CString.
David Wilkinson
Tom
"David Wilkinson" <no-r...@effisols.com> wrote in message
news:%23XvWbvD...@TK2MSFTNGP06.phx.gbl...