C++ 清除绳子
C++ Clearing wstring
我的问题是,过去处理字符串的方法不适用于 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被上一个周期的文本完全填满。
std::wstring::clear
应该可以工作,因为它和std::string
都是std::basic_string
s。 如果您遇到问题,请查看 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 链接。
相关文章:
- 清除前检查矢量
- ifstream文件在从行中读取时被清除
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- 如何清除/清空已打开的文件C++
- 如何在 c++ 中清除矢量容量?
- 可以清除递归函数中的变量吗?
- 在清除 istream 之前,我不应该需要取消获取它吗?
- 结构成员在访问时被清除
- 清除输入缓冲区后未提取字符串流
- SDL_ttf清除我之前和将来的所有渲染
- 如何使用内存集清除字符数组
- 有没有办法在c ++中清除空数组,请检查下面的代码以获取说明
- QTreeWidgetItem 设置不可选择将清除选择
- libQGLViewer 如何在没有清除缓冲区的情况下绘制
- 清除具有已删除赋值运算符的成员的类实例
- 清除结构向量时会发生什么?
- 显式清除 std::move 之后的源资源
- C++ - 重置字符串流不会重置获取位置或清除标志吗?
- std::cin 在读取 EOF 并清除后不再读取
- 清除在 main() 中分配的堆栈内存?