编一个程序,从 string 对象中去掉标点符号。要求输入到程序的字符串必须含有标点符号,输出结果则是去掉标点符号后的 string 对象。

来源:互联网 发布:11月9日淘宝交易指数 编辑:程序博客网 时间:2024/05/17 00:56
#include <iostream>
#include <ctype.h>
#include <string>


using namespace std;
int main(void)
{
string sour_str,out_str;//sour_str为用户输入的字符串,out_str为去掉标点的字符串
cout<<"Please input a string:";//输入字符串
cin>>sour_str;
for(int index=0;index<sour_str.size();index++)
{
if(!ispunct(sour_str[index]))
out_str+=sour_str[index];
}
cout<<"Delete punctuation character of the: "<<sour_str<<" is "<<out_str<<endl;
return 0;
}
0 0
原创粉丝点击