输入3个字符串,按由小到大的顺序输出,用C加加,并且使用指针
时间: 2024-01-02 08:49:41 浏览: 31
```c++
#include<iostream>
#include<string>
using namespace std;
int main() {
string str1, str2, str3;
cout << "请输入3个字符串:" << endl;
cin >> str1 >> str2 >> str3;
string *p1 = &str1;
string *p2 = &str2;
string *p3 = &str3;
if (*p1 > *p2) {
string *temp = p1;
p1 = p2;
p2 = temp;
}
if (*p1 > *p3) {
string *temp = p1;
p1 = p3;
p3 = temp;
}
if (*p2 > *p3) {
string *temp = p2;
p2 = p3;
p3 = temp;
}
cout << "按由小到大的顺序输出:" << endl;
cout << *p1 << " " << *p2 << " " << *p3 << endl;
return 0;
}
```