分享

比较string对象及其+操作 79

 木俊 2018-08-02
#include<iostream>
using namespace std;
#include<string>
int main()
{
 //string 的empty和size操作
string s1;
if (s1.empty())
{
cout << "空的" << endl;//空的
}
else
{
cout << "不是空的" << endl;
}
string s2("12345");
cout << "s2的位数:" << s2.size() << endl; //s2的位数:5
auto a = s2.size();//a=5;,a.size()返回的是无符号数,
int b = -10;
if (a > b)//int 和 无符号 相比较,int 转换为无符号
{
cout << "a>b" << endl;
}
else
{
cout<< "a<b" << endl;
}
//  a<b

//sring的==  >  <

//string 的+

string a1 = "aga";
string a2 = "agrq";
string a3 = a1 + a2;
cout << "a3: " << endl;

string a4 = "sagrwa" + a3;
cout << "a4:" << a3 << endl;
//string a5 = "sgws" + "sgwgger";//报错 string +,左右必有一个string,不能全是字面值
system("pause");
}

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约