您的位置:首页 > 编程语言 > C语言/C++

C++ 定义string类型变量

2014-02-24 12:35 295 查看
#include<iostream>
#include<string>

using namespace std;

int main()
{

string s1;//s1为空串
/*	s1 = "aaa";
string s2(s1); //s2复制s1
if(s2 == s1){
cout<<"string s2(s1): s2 = s1"<<endl;
}
s1 = "begin";
cout<<s2<<endl;
s1 = "change";
cout<<s2<<endl;*/

s1 = "aaa";
string s2 = s1;
if(s2 == s1){
cout<<"string s2=s1: s2 = s1"<<endl;
}
s1 = "begin";
cout<<s2<<endl;
s1 = "change";
cout<<s2<<endl;

//	string s3("value");
string s3="value";
string s4(10, 'c');//将s4初始化为10个字符‘c’

cout<<s3<<endl<<s4<<endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: