我的问题是,没有任何用于字符串的方法适用于wstring。
所以我问我如何能够轻松地清除wstring
以达到美学目的。
我的代码现在:
while (!foundRightOne)
{
wstring cTitle;
ForegroundWindow = GetForegroundWindow();
cout << "FRGW " << ForegroundWindow << endl;
int len = GetWindowTextLengthW(ForegroundWindow) + 1;
wchar_t * windowTitle = new wchar_t[len];
GetWindowTextW(ForegroundWindow, windowTitle, len);
title += windowTitle;
// OUTPUT
cTitle = L"Title: ";
cTitle += title;
wcout << cTitle << endl;
cTitle = ' ';
//OUTPUT
keyPress = getchar();
system("CLS");
if (keyPress == 'y' || keyPress == 'Y')
{
foundRightOne = true;
}
}
基本上,当我按y
或Y
时,它会循环播放,当我看到正确的cTitle
时,按下 ~20 周期后,cTitle会完全填满来自最后一个周期的文本。
答案 0 :(得分:1)
std::wstring::clear
应该有用,因为它和std::string
都是std::basic_string
。如果您遇到问题,请查看std::basic_string文档。
#include <iostream>
int main()
{
std::string regularString("regular string!");
std::wstring wideString(L"wide string!");
std::cout << regularString << std::endl << "size: " << regularString.size() << std::endl;
std::wcout << wideString << std::endl << "size: " << wideString.size() << std::endl;
regularString.clear();
wideString.clear();
std::cout << regularString << std::endl << "size: " << regularString.size() << std::endl;
std::wcout << wideString << std::endl << "size: " << wideString.size() << std::endl;
}
输出:
regular string!
size: 15
wide string!
size: 12
size: 0
size: 0
以下是该代码的ideone链接。