字符串转换大小写如下:

 #include "stdafx.h"
#include <iostream>
#include <string> using namespace std; int main()
{
string str = "helloworld";
for (auto begin = str.begin(); begin != str.end(); ++begin)
{
*begin = toupper(*begin);
} cout << str << endl; system("PAUSE");
return ;
}

删除字符串中所有的大写字母:

 #include "stdafx.h"
#include <iostream>
#include <string> using namespace std; int main()
{
string str("helloWorld");
for (auto begin = str.begin(); begin != str.end();)
{
if (isupper(*begin))
{
begin = str.erase(begin);
continue;
}
++begin;
} cout << str << endl; system("PAUSE");
return ;
}

用vector对象初始化string :

 #include "stdafx.h"
#include <iostream>
#include <string>
#include <vector> using namespace std; int main()
{
vector<char> vect;
char arry[] = {'h','e','l','l','o'};
vect.insert(vect.begin(),arry,arry+);
char *pc = new char[vect.size()+];
int i = ;
for (vector<char>::iterator begin = vect.begin(); begin != vect.end(); ++begin)
{
pc[i] = *begin;
++i;
}
pc[vect.size()] = '\0';
string str(pc);
delete [] pc;
cout << str << endl;
system("PAUSE");
return ;
}
04-17 09:16