std::string to LPCTSTR

后端 未结 7 1356
甜味超标
甜味超标 2021-02-19 10:30

New version of the typical question of how to convert from std::string to LPCTSTR.

Reading from different SO posts I learnt that I should do th

7条回答
  •  忘掉有多难
    2021-02-19 11:28

    As this question pops up when you try to find "(std::) string to LPCTSTR"

    Here's a way how to convert&pass std::string as LPCTSTR using wstring

    string path_str = "Yay!"; //your string containing path
    wstring path_wstr( path_str.begin(), path_str.end() );
    //then this should work:
    CreateDirectory(path_wstr.c_str(),NULL);
    

    IMPORTANT Note by Adrian McCarthy:

    This is fine if the source string is ASCII or if it's ANSI and the current code page is Windows-1252 (which is very similar to Latin-1). If the source is UTF-8 or another code page, then this just hides the problem.

提交回复
热议问题