1 #include <string> 2 #include <iostream> 3 #include <cctype> 4 using std::cin; 5 using std::cout; 6 using std::endl; 7 using std::string; 8 using std::cerr; 9 int main() 10 { 11 string s; 12 string result = ""; 13 cout<<"Please input a string which must have punctuations."<<endl; 14 cin>>s; 15 int punct_cnt = 0; 16 for(string::size_type index = 0; index < s.size(); ++index){ 17 if(ispunct(s[index])){ 18 ++punct_cnt; 19 }else { 20 result += s[index]; 21 } 22 } 23 if(punct_cnt > 0){ 24 cout << "The result of " + s + " without punctions is " + result<<endl; 25 }else { 26 cerr << "Wrong input.The string did not has punctions."<<endl; 27 } 28 system("pause"); 29 return 0; 30 }
转载于:https://www.cnblogs.com/zhaokaikai/archive/2012/09/29/2708671.html