C++——输入3个字符串,按由小到大的顺序输出。用指针或引用方法处理。

没注释的源代码

#include <iostream>

#include <string>

#include <stdio.h>

using namespace std;

void swap(string&str1,string&str2);

int main()

{

string a=" ",

b=" ",

c=" ";

char *p1=&a[0],*p2=&b[0],*p3=&c[0];

cout<<"please input line p1,p2,p3:"<<endl;

gets(p1);

gets(p2);

gets(p3);

if(a>b) swap(a,b);

if(a>c) swap(a,c);

if(b>c) swap(b,c);

cout<<"now the order is:"<<endl<<a<<endl<<b<<endl<<c<<endl;

return 0;

}

void swap(string&str1,string&str2)

{

string temp;

temp=str1;

str1=str2;

str2=temp;

}

相关推荐
csbysj202037 分钟前
Vue.js 混入:深入理解与最佳实践
开发语言
Gerardisite2 小时前
如何在微信个人号开发中有效管理API接口?
java·开发语言·python·微信·php
Want5952 小时前
C/C++跳动的爱心①
c语言·开发语言·c++
lingggggaaaa2 小时前
免杀对抗——C2远控篇&C&C++&DLL注入&过内存核晶&镂空新增&白加黑链&签名程序劫持
c语言·c++·学习·安全·网络安全·免杀对抗
phdsky3 小时前
【设计模式】建造者模式
c++·设计模式·建造者模式
H_-H3 小时前
关于const应用与const中的c++陷阱
c++
coderxiaohan3 小时前
【C++】多态
开发语言·c++
gfdhy3 小时前
【c++】哈希算法深度解析:实现、核心作用与工业级应用
c语言·开发语言·c++·算法·密码学·哈希算法·哈希
百***06013 小时前
SpringMVC 请求参数接收
前端·javascript·算法
Eiceblue3 小时前
通过 C# 将 HTML 转换为 RTF 富文本格式
开发语言·c#·html