Re: LPCTSTR to std::string
doesn't seem to work well in 16-bit characters (foreign characters), the
assignment returns a trash string...
BOOL Cdecom7Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
std::string fileName;
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
fileName = lpszPathName; <<<< trash!!!
// SetFileName(lpszPathName);
m_pFile = new cFile();
m_pFile->OpenfileEx(fileName);
// TODO: Add your specialized creation code here
return TRUE;
}
"Abdo Haji-Ali" <ahali@inframez.org_use_com_instead> ???g???l???s?D:uXYOkoI5GHA.2596@TK2MSFTNGP06.phx.gbl...
"Jacky Luk" <jl@knight.com> wrote in message
news:uT4bsfI5GHA.2536@TK2MSFTNGP06.phx.gbl...
Hi
How to cast a LPCTSTR to std::string?
In this case it's not a "cast". It's an "assignment" or "copying"...
Do I just
m_fileName = lpszPathName;
This is the way to do it (it's called assignment)
or
strcpy (m_fileName, lpszPathName);
If you try this one it would give a compiler error, because you can't
"cast"
an std:string to char* (only const char*)
or
there is something more useful?
What do you mean by useful? Easier? Faster? Funnier :)
--
Abdo Haji-Ali
Programmer
In|Framez