C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ String clear()

C++ String clear()

此函数删除元素,成为一个空字符串。

语法

考虑字符串str。语法为:
str.clear();

参数

此函数不包含任何参数。

返回值

此函数不包含返回任何值。

示例

让我们看一个简单的clear()函数示例:
#include<iostream>
using namespace std;
int main()
{
stringstr;
cout<<?Enter some lines about lidihuo and write dot character to finish the sentence?<<?\n?;
cout<<?if you want to clear the text, press d?<<?\n?;
do{
charch =cin.get();
str+=ch;
if(ch==?d?)
str.clear();
}while(ch!=?.?);
return 0;
}
输出:
Enter some lines about lidihuo and write dot character to finish the sentence
if you want to clear the text, press d
此示例显示clear()函数的工作方式。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4