• C++ primer 第3章 ex3.10


    #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;
    }

  • 相关阅读:
    22:django 配置详解
    21:序列化django对象
    20:django中的安全问题
    19:django 分页
    HTML 标签(一)
    流程图学习绘制
    HTTP原理
    终端的颜色代码
    Python 进程 线程总结
    Python Select模型
  • 原文地址:https://www.cnblogs.com/fuyou/p/2741877.html
Copyright © 2020-2023  润新知