#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
//根据value的值输出ture或者false
//title为提示文字
inline void test(const char *title,bool value){
cout <<title <<"returns"<<(value?"ture":"false")<<endl;
}
int main(){
string s1 = "DEF";
cout<<"s1 is "<<s1 << endl;
string s2;
cout <<"Please enter s2 \n";
cin >>s2;
cout << "length of s2: "<<s2.length()<<endl;
//比较运算符的测试
test("s1<=\"ABC\"",s1 <= "ABC");
test("\"DEF\"< = s1 ","DEF"<=s1);
//连接运算符的测试
s2 += s1;
cout<<"s2= s2 + s1:"<<s2<<endl;
cout<< "length of s2:"<<s2.length()<<endl;
return 0;
}
string 类的简单运用
最新推荐文章于 2024-10-29 15:37:06 发布
本文展示了一个使用C++进行字符串操作和比较的示例,包括读取输入、字符串连接和使用条件判断来比较字符串。代码中包含了字符串的声明、读取用户输入、长度检查、比较运算符的使用以及字符串连接的演示。
2821

被折叠的 条评论
为什么被折叠?



