/* 2009-3-1 3-10 * 编写一个程序,从string对象中去掉标点符号,并且要求输入到程序中的字符串要含有标点符号 *,输出的结果是去掉标点符号后的string对象 */ #include <iostream> #include <string> #include <stdlib.h> using namespace std; //我没有作出来啊!!! //一下是参考答案,关键点在于我不知道如何做那个连接,字符串是可以和字符做"+" int main() { string sz,result_str; bool has_punct = false; char ch; cout << "Enter a string :" << endl; getline(cin, sz); for (string::size_type index =0 ;index != sz.size(); ++index) { ch = sz[index]; if (ispunct(ch)) { has_punct = true; } else result_str += ch; } if (has_punct) { cout << "Result is:" << endl << result_str <<endl; } else cout << "no puctuation character in the string" << endl; system("pause"); return 0; }