ST::String::C++中的清除

字符串内容被设置为空字符串,删除之前的任何内容,从而将其大小保留为0个字符。 参数: 没有一个 返回值: 没有一个

null
void string ::clear ()
- Removes all characters (makes string empty)
- Doesn't throw any error
- Receives no parameters and returns nothing

// CPP code to illustrate
// clear() function
#include <iostream>
#include <string>
using namespace std;
// Function to demo clear()
void clearDemo(string str)
{
// Deletes all characters in string
str.clear();
cout << "After clear : " ;
cout << str;
}
// Driver code
int main()
{
string str( "Hello World!" );
cout << "Before clear : " ;
cout << str << endl;
clearDemo(str);
return 0;
}


输出:

Before clear : Hello World!
After clear : 

相关文章: std::string::erase 本文由 萨希·提瓦里 .如果你喜欢极客(我们知道你喜欢!)如果你想投稿,你也可以用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享