My 정리 :
std::string s2 = (LPSTR)pcds->lpData;
To "convert" a std::string to a LPCSTR depends on the exact context but usually calling .c_str() is sufficient.
This works.
void TakesString(LPCSTR param);
void f(const std::string& param)
{
TakesString(param.c_str());
}Note that you shouldn't attempt to do something like this.
LPCSTR GetString()
{
std::string tmp("temporary");
return tmp.c_str();
}The buffer returned by .c_str() is owned by the std::string instance and will only be valid until the string is next modified or destroyed.
정의 -----------------------
LPSTR - (long) pointer to string - char *
LPCSTR - (long) pointer to constant string - const char *
LPWSTR - (long) pointer to Unicode (wide) string - wchar_t *
LPCWSTR - (long) pointer to constant Unicode (wide) string - const wchar_t *
LPTSTR - (long) pointer to TCHAR (Unicode if UNICODE is defined, ANSI if not) string - TCHAR *
LPCTSTR - (long) pointer to constant TCHAR string - const TCHAR *
std:string 정의 페이지
http://www.cplusplus.com/reference/string/string/
원본 페이지 :
from: http://stackoverflow.com/questions/1200188/how-to-convert-stdstring-to-lpcstr
64 28 | |
add a comment |
58 |
| ||||||||
|
103 | Call c_str() to get a const char * (LPCSTR) from a std::string. It's all in the name:
You can ignore the L (long) part of the names -- it's a holdover from 16-bit Windows. | ||||||||
|
25 | These are Microsoft defined typedefs which correspond to: LPCSTR: pointer to null terminated const string of LPSTR: pointer to null terminated char string of LPCWSTR: pointer to null terminated string of const LPWSTR: pointer to null terminated string of To "convert" a This works. Note that you shouldn't attempt to do something like this. The buffer returned by To convert a e.g. | ||||||||
7 | Using
| |||
3 | The One minor tweak would be to use Also, if you need to work with wide strings to start with, you can use | |||
2 | The conversion is simple: std::string str; LPCSTR lpcstr = str.c_str(); | ||
2 | Converting is simple: One thing to be careful of here is that c_str does not return a copy of myString, but just a pointer to the character string that std::string wraps. If you want/need a copy you'll need to make one yourself using strcpy. | ||||
1 | The easiest way to convert a
|
'Programming > C++' 카테고리의 다른 글
| VS2013의 찾기 결과창에 다음이동 F4 key로 변경 (1) | 2015.04.09 |
|---|---|
| SendMessage C#-> C++ (빠른 속도 지향) (0) | 2015.04.07 |
| [펌] std::string과 std::wstring간의 문자열 변환. (0) | 2015.04.07 |

