1、处理string对象的字符常用方法如下:
isalnum():判断字符是否是字母或数字;
isalpha():判断字符是否是字母;
iscntrl():判断字符是否是控制字符;
isdigit():判断字符是否是数字;
isgraph():判断字符是否是可打印的非空格字符;
ispunct():判断字符是否是标点符号;
isspace():判断字符是否是空白字符;
isupper():判断字符是否是大写字母;
isxdigit():判断字符是否是十六进制数;
toupper():转换为大写字母;
tolower():转换为小写字母。
2、使用迭代器寻找和删除string对象中的所有大写字母【string 可以跟vector一样,使用erase函数】 (c++primer 习题9.36)
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <cstring>
#define ARRAY_LENGTH 5
using namespace std;
int main(int argc, char * argv[])
{
string str;
cout<<"input alpha"<<endl;
getline(cin,str);
for(string::iterator iter=str.begin();iter!=str.end();){
if(isupper(*iter)){
iter = str.erase(iter);
}else{
++iter;
}
}
for(string::iterator iter = str.begin();iter!=str.end();++iter){
cout<<*iter;
}
return 0;
}