#include <iostream>
using namespace std;
int main()
{
string str_a(5,'a');
cout << str_a <<endl;
string str_b = "abcde";//char * --> string
cout << str_b <<endl;
const char *bb = "fgh";
string e(bb);
cout << e <<endl;
str_b = str_b + e;//追加
cout << str_b <<endl;
string str_g = str_b; // ‘ = ’
cout << str_g << endl;
for (int i = 0; i < str_g.length(); i++)//字符遍历
{
/* code */
//cout <<str_g[i] <<endl;//数组方式
cout << str_g.at(i) << endl;//at方法 方式
}
string str_i = "hello world ,is a demo code";
int index = str_i.find('w',1);//查找
cout << index << endl;//6
str_i.replace(6,5,"Vip");//替换
cout << str_i << endl;
const char *pp =str_i.c_str();//string --> char *
return 0;
}
using namespace std;
int main()
{
string str_a(5,'a');
cout << str_a <<endl;
string str_b = "abcde";//char * --> string
cout << str_b <<endl;
const char *bb = "fgh";
string e(bb);
cout << e <<endl;
str_b = str_b + e;//追加
cout << str_b <<endl;
string str_g = str_b; // ‘ = ’
cout << str_g << endl;
for (int i = 0; i < str_g.length(); i++)//字符遍历
{
/* code */
//cout <<str_g[i] <<endl;//数组方式
cout << str_g.at(i) << endl;//at方法 方式
}
string str_i = "hello world ,is a demo code";
int index = str_i.find('w',1);//查找
cout << index << endl;//6
str_i.replace(6,5,"Vip");//替换
cout << str_i << endl;
const char *pp =str_i.c_str();//string --> char *
return 0;
}