字符串内容设置为空字符串,将擦除任何先前的内容,因此其大小保留为0个字符。
参数:无
返回值:无
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
#include
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 :
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。