C++ C++;清管环
我的问题是,没有一个用于处理字符串的方法可以处理wstring。 所以我想问的是,为了美观起见,我如何能够轻松地清除C++ C++;清管环,c++,wstring,C++,Wstring,我的问题是,没有一个用于处理字符串的方法可以处理wstring。 所以我想问的是,为了美观起见,我如何能够轻松地清除wstring 我现在的代码: while (!foundRightOne) { wstring cTitle; ForegroundWindow = GetForegroundWindow(); cout << "FRGW " << ForegroundWindow << end
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;
}
}
while(!foundRightOne)
{
wstring cTitle;
ForeGroundIndow=GetForeGroundIndow();
coutstd::wstring::clear
应该可以工作,因为它和std::string
都是std::basic_string
s。如果遇到问题,请查看文档
#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;
}
这里是该代码的链接。std::string
和std::wstring
除了存储的字符类型外,完全相同。无论如何,空格不是清除的字符串,字符文字也不是宽字符,就像字符串文字不是宽字符串一样。代码不是测试用例。请提供定义n的“标题”谢谢。现在我真的很困惑。在检查size()后,它显示为0,但它仍然输出旧标题。[链接]-Screenshot@Ufonautas您是否尝试将其设置为空字符串?cTitle=“
或通过cTitle=std::wstring()重新初始化它
regular string!
size: 15
wide string!
size: 12
size: 0
size: 0