您的位置:首页 > 其它

计算标点符号

2016-01-11 14:40 253 查看
#include <iostream>
#include <string>
//#include <ctype.h>  //这是标准C语言的头文件,
#include <cctype>  //C++使用C语言的头文件只要在前面加上c后边的点h省去,

using namespace std;

int main ()
{
string v1("xiao,, cui !!");
string::size_type punct_cnt = 0; //计数器:标点符号的个数
for(string::size_type index = 0; index != v1.size(); ++index)
{
if(ispunct(v1[index]))  //ispunct(c)是判断字符串是不是标点符号,
++punct_cnt;
}

cout << "这个字符串里有"
<< punct_cnt << "个标点符号." << endl;

for(string::size_type index = 0; index != v1.size(); ++index)
v1[index] = toupper(v1[index]);//toupper(c)是字符变成大写

cout << v1 << endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: