zoukankan      html  css  js  c++  java
  • Exercice_3.10_去掉string对象中的标点符号

    //去掉string对象中的标点符号
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
        string str, result_str;
        bool has_punct = false; //用于记录有无标点
        char ch;
    
        //输入字符串
        cout << "Enter strings." << endl;
        getline(cin, str);
    
        //去掉字符串中的标点 换个思路也就是保存不是标点的字符
        for (string::size_type index = 0; index != str.size(); ++index)
        {
            ch = str[index];
            if (ispunct(ch))
                has_punct = true;
            else
                result_str += ch;
        }
    
        //输出结果
        if(has_punct)
            cout << "Result: " << result_str << endl;
        else
        {
            cout << "No punctuations in the strings." << endl;
            return -1;
        }
    
        return 0;
    }
    

  • 相关阅读:
    c++
    zjoi 力
    poj 3415
    [SDOI2014]旅行
    模板测试
    [WC2006]水管局长
    HDU5730
    [NOI2014]魔法森林
    [NOI2012]骑行川藏(未完成)
    [NOI2012]随机数生成器
  • 原文地址:https://www.cnblogs.com/mrbourne/p/9959477.html
Copyright © 2011-2022 走看看