C ++字符串交换字符位置 [英] C++ string swap character places

查看:682
本文介绍了C ++字符串交换字符位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法交换字符串中的字符位置?例如,如果我有03/02我需要得到02/03
任何帮助。

is there a way to swap character places in a string? For example if I have "03/02" I need to get "02/03". Any help is appreciated!

推荐答案

当然:

#include <string>
#include <algorithm>

std::string s = "03/02";
std::swap(s[1], s[4]);

这篇关于C ++字符串交换字符位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆