gpt4 book ai didi

c++ - 将字符串转换为 LPWSTR

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:53:21 27 4
gpt4 key购买 nike

<分区>

我很难将字符串转换为 LPWSTR,因此我可以使用 PathStripToRoot() 函数。

MSDN 文档说我需要 LPTSTR 变量 ( http://msdn.microsoft.com/en-us/library/windows/desktop/bb773757(v=vs.85).aspx ),但是 Visual Studio 2013 说我需要 LPWSTR

这是我的函数的代码片段:

fileStat fileCreate(const string& targetFile)
{
fileStat filez;

fstream file(targetFile.c_str());
if (!file)
{
cout << "File does not exist" << endl;
}

std::ifstream in(targetFile, ios::binary | ios::ate);
int a = in.tellg();
cout << "File size(bytes): " << in.tellg() << endl << endl;
file.close();


wstring stemp = strChange(targetFile);
LPCWSTR result = stemp.c_str();

/* Tried the below code but that did not work
LPWSTR ws = new wchar_t[targetFile.size() + 1];
copy(targetFile.begin(), targetFile.end(), ws);
ws[targetFile.size()] = 0;
*/

cout<<"\n\n"<<PathStripToRoot(ws)<<"\n\n";

...
filez.fileSize = a;
return filez;
}

很多人都说要使用 MultiByteToWideChar() 函数,但我查看了 MSDN 文档,却不知道它是如何工作的。有没有比使用 MultiByteToWideChar() 更简单的方法?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com