RE: Cstring, string ,and char[]
// Suppose
CString str;
std::string s;
char buf[SIZE];
// from CString to std::string
s = str;
// from std::string to CString
str = s.c_str();
// to char[]
_tcscpy(buf, str);
_tcscpy(buf, s.c_str());
// from char[]
str = buf;
s = buf;
Also, beware of unicode. If UNICODE is defined, you should convert between
unicode and ansi versions. Better to use TCHAR instead of char and
std::basic_string<TCHAR> instead of std::string.
--
======
Arman
"Asm23" wrote:
I have a problems on the file io.
when I use the dilog box to pick a txt file.
code is like below.
CFileDialog dlg(.......);
if(dlg.DoModal() == IDOK)
{ Cstring a;
a= dlg.GetPathName();
}
the "a" will assigned a filename of the txt file.
a is a Cstring type variable.
but in standard c++ ,I use the
string p;
p=????;//p is the file full path.
inFile.open(p);
if (!inFile)
{
cout << "Unable to open file";
return;
}
where p is a standard string class.
My question is How can I traslate among Cstring ,string and char[].
Is there any common methods?
Thank you! everyone who read my post!