任务1
#include<iostream>
using namespace std;
void pass1()
{
char str[100];
cin.getline(str, 100);
cout << str << endl;
}
任务2
#include<iostream>
#include<string>
using namespace std;
void pass2()
{
string s1, s2;
cin >> s1 >> s2;
if (s1 > s2) cout << s1 + s2 << endl;
else cout << s2 + s1 << endl;
}
任务3
#include<iostream>
#include<string>
using namespace std;
void pass3()
{
string s1, s2;
cin >> s1 >> s2;
if (s1.find(s2) == s1.npos) cout << "no!" << endl;
else cout << s1.find(s2) << endl;
}
本文介绍了三种基本的字符串操作方法:读取并输出字符串、比较两个字符串并按顺序连接它们以及检查一个字符串是否包含另一个字符串。这些操作对于初学者理解和掌握C++中的字符串处理非常有用。
1万+

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



