回复:(songying)我也遇到过这种情况,不知道是怎么...
那就介绍一下std::string用法
string来代替char * 数组,
1、Define
string s1 = "hello";
string s2 = "world";
string s3 = s1 + "," + s2 +"!\n";
2、append
s1 += ",shanshan\n";
3、Compare
if(s1 == s2)
.....
else if(s1 == "hello")
.....
4、 string 重载了许多操作符,包括 +, +=, <, =, , [], <<, >>等,正式这些操作符,对字符串操作非常方便
#include <string>
#include <iostream>
using namespace std;
int main(){
string strinfo="Please input your name:";
cout << strinfo ;
cin >> strinfo;
if( strinfo == "winter" )
cout << "you are winter!"<<endl;
else if( strinfo != "wende" )
cout << "you are not wende!"<<endl;
else if( strinfo < "winter")
cout << "your name should be ahead of winter"<<endl;
else
cout << "your name should be after of winter"<<endl;
strinfo += " , Welcome to China!";
cout << strinfo<<endl;
cout <<"Your name is :"<<endl;
string strtmp = "How are you? " + strinfo;
for(int i = 0 ; i < strtmp.size(); i ++)
cout<<strtmp[i];
return 0;
}
不过这些都是以前的版本了!
现在不常用了,在读以前的源代码时会碰到!