输出string中标点的个数

#include <iostream>
#include <string>
#include <cctype>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
    string str("some string!!!");
    string::size_type punct_cnt = 0;
    for (string::size_type ix = 0; ix != str.size(); ++ix)
        if (ispunct(str[ix]))
            ++punct_cnt;
        cout << punct_cnt << " punctuation character" << endl;
    return 0;
}

1:c中使用的是name.h 而c++中使用的是cname

posted on 2013-02-16 11:14  小风儿_xf  阅读(151)  评论(0编辑  收藏  举报

导航