Re: LPCTSTR to std::string

Tech-Archive recommends: Speed Up your PC by fixing your registry



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@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> ¼¶¼g©ó¶l¥ó·s»D:uXYOkoI5GHA.2596@xxxxxxxxxxxxxxxxxxxxxxx
"Jacky Luk" <jl@xxxxxxxxxx> wrote in message
news:uT4bsfI5GHA.2536@xxxxxxxxxxxxxxxxxxxxxxx
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




.