STL string用法

#include<iostream>
#include<string.h>
#include<cmath>
#include<string>
#include<vector>
#include<set>

using namespace std; 


int main(){
	string str="abcd";
	cout<<str<<endl;
	printf("str.length()=%d\n",str.length());
	printf("str[4]=%d\n",str[4]);
	str.insert(3,"*hello*");
	cout<<"after str.insert *hello*:"<<str<<endl;
	char str2[str.length()]; 
	strcpy(str2,str.c_str());
	printf("str.c_str()=%s\n",str2); 
	
	
	string str1;
	printf("string 输入空格,以回车结束\n");
	getline(cin,str1);
	cout<<str1<<endl;
	printf("如果输入hello world,打印第六个字符ASCII码,即空格%d\n",str1[5]);
	return 0; 

}
©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页