C++计算一个字符串中标点符号的个数

#include 
#include 
using namespace std;

int main(int argc, char *argv[])
{
    string s("hello world!!!");
    decltype(s.size()) punct_cnt=0;
    for(auto c:s)
        if(ispunct(c))
            ++punct_cnt;

    cout<
decltype用法:http://baike.baidu.com/link?url=jA9LjLVMsOI_dHD8tTmsLfPfkFvTEVMTi4vUQZaowBe69XfQ87gPHyCd5jxGUOsbbjvehLQx0OZ_slpBayNc40SI4vhFIrQ01np9IBLhCAS

你可能感兴趣的:(C/C++小技巧)