#define _SCL_SECURE_NO_WARNINGS
#include "iostream"
using namespace std;
#include "string"
#include "algorithm"
void main21()
{
string s1 = "aaaa";
string s2("bbbb");
string s3 = s2;
string s4(10,'a');
cout << "s1:" << s1 << endl;
cout << "s2:" << s2<< endl;
cout << "s3:" << s3 << endl;
cout << "s4:" << s4 << endl;
}
void main22()
{
string s1 = "abcdefg";
for (int i = 0; i < s1.length(); i++)
{
cout << s1[i] << " ";
}
cout << endl;
for (string::iterator it = s1.begin(); it != s1.end(); it++)
{
cout << *it << " ";
}
cout << endl;
try
{
for (int i = 0; i < s1.length()+3; i++)
{
cout << s1.at(i) << " ";
}
}
catch (...)
{
cout << "发生异常\n" << endl;
}
}
void main23()
{
string s1 = "aaaabbbb";
printf("s1:%s\n", s1.c_str());
char buf1[128];
s1.copy(buf1,3,0);
cout << "buf1:" << buf1 << endl;
}
void main24()
{
string s1 = "aaaa";
string s2 = "bbbb";
s1 = s1 + s2;
cout << s1 << endl;
string s3 = "3333";
string s4 = "4444";
s3.append(s4);
cout << "s3:" << s3 << endl;
}
void main25()
{
string s1 = "wem hello wem 1111 wem 2222 wem 3333";
int index=s1.find("wem", 0);
cout << "index:" << index<<endl;
int offindex = s1.find("wem", 0);
while (offindex != string::npos)
{
cout << "offindex:" << offindex << endl;
offindex = offindex + 1;
offindex=s1.find("wem", offindex);
}
int offindex1 = s1.find("wem", 0);
while (offindex1 != string::npos)
{
cout << "offindex:" << offindex1<< endl;
s1.replace(offindex1,3,"WBM");
offindex1 = offindex1 + 1;
offindex1 = s1.find("wem", offindex1);
}
cout << "替换的结果" << s1 << endl;
}
void main26()
{
string s1 = "hello1 hello2 hello3";
string::iterator it= find(s1.begin(), s1.end(), 'l');
if (it != s1.end())
{
s1.erase(it);
}
cout << s1 << endl;
s1.erase(s1.begin(), s1.end());
cout << s1 << endl;
cout << s1.length() << endl;
string s2 = "BBB";
s2.insert(0, "AAA");
s2.insert(s2.length(),"CCC");
cout << s2 << endl;
}
void main27()
{
string s1 = "AAAbbb";
transform(s1.begin(), s1.end(), s1.begin(),toupper);
cout << s1 << endl;
string s2 = "AAAbbb";
transform(s2.begin(), s2.end(),s2.begin(), tolower);
cout << s2 << endl;
}
void main000()
{
main27();
system("pause");
}