#pragma once #include <string> #include <iostream> #include <cctype> using namespace std; void getstring() { string result_str,userInput_str; bool hasPunct=false; cout<<"请输入字符传:"<<endl; cin>>userInput_str; for(string::size_type i=0;i<userInput_str.size();i++) { char check=userInput_str[i]; if (ispunct(check)) { hasPunct=true; } else { result_str += check; } } if (hasPunct) { cout<<"去标点后的字符串:"<<result_str<<endl; }else { cout<<"输入有误,输入必须包含标点!"<<endl; } } int main() { while(true) { cout << endl << "1) 输出去标点后的字符串" << endl; cout << "2) 退出" << endl << endl; cout << "请选择 [1], [2] : "; string userInput; getline(cin,userInput); if(userInput.size() == 0) continue; const char ch = userInput[0]; if(ch == '2') break; else if(ch =='1') getstring(); else cout << endl << "Input error. Enter 1, 2 and [Enter]."<< endl; } return 0; }