以下代码配合该大佬博客食用
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void test1()
{
string a;
string b("asdf");
string c="adfasdf";
string d=c;
string e(3,'e');
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
cout<<d<<endl;
cout<<e<<endl;
}
void test2()
{
string a="absfasdfa";
for(int i=0;i<a.length();i++)
cout<<a[i]<<" ";
cout<<endl;
string::iterator it;
for(it=a.begin();it!=a.end();++it)
cout<<*it<<" ";
cout<<endl;
}
void test3()
{
string s1="asdfadsf";
printf("%s\n",s1.c_str());
char buf[128]={0};
s1.copy(buf,5,2);
cout<<buf<<endl;
}
void test4()
{
string a="adsf";
string b="df";
cout<<(a<b)<<endl;
cout<<a.compare(b)<<endl;
string c="1000";
string d="20";
cout<<(c<d)<<endl;
cout<<c.compare(d)<<endl;
}
void test5()
{
string a="aaaa";
string b("bbbb");
a+=b;
cout<<a<<endl;
string c="cccc";
string d="dddd";
c.append(d);
cout<<c<<endl;
}
void test6()
{
string a="abcdecg";
string b=a.substr(2,3);
cout<<b<<endl;
cout<<a.find('c',0)<<endl;
cout<<a.find('c',3)<<endl;
cout<<a.find('i',0)<<endl;
cout<<a.find("dec",0)<<endl;
cout<<a.find("fds",0)<<endl;
cout<<a.rfind('c',4)<<endl;
string d="aaaaaa";
d.replace(3,4,"bbbbbb");
cout<<d<<endl;
string e="asdfa";
d.swap(e);
cout<<d<<endl;
}
void test7()
{
string a="aaaaaaaaaa";
a.insert(3,"bbbbbbbbbb");
cout<<a<<endl;
a.insert(5,3,'c');
cout<<a<<endl;
a.erase(0,10);
cout<<a<<endl;
}
int main()
{
return 0;
}