c++ 如何在 cout 之前洗牌/混合字符串
c++ How to shuffle/mix a string before cout?
请参考以下代码
random_shuffle(cq.begin(), cq.end());
cout << cq ;
据我了解,我已经将两根字符串c
和q
连接到一个cq
。然后我想在cout
之前洗牌/混合它.我该怎么做?
提前感谢您的回答
#include <iostream>
#include <random>
#include <algorithm>
int main()
{
std::string str = "StackOverflow";
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(str.begin(), str.end(), g);
std::cout << str.c_str() << std::endl;
return 0;
}
您可以阅读有关 http://en.cppreference.com/w/cpp/algorithm/random_shuffle 的更多详细信息
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 返回混合 \ 和 / 的文件系统路径字符串方法
- c++ 如何在 cout 之前洗牌/混合字符串
- 在同一行中读取混合输入(字符串/浮点数),并将其存储在数组中
- boost::p rogram_option::store 在选项字符串包含混合语言字符时引发异常
- 使用CIN和/或字符串读取带有混合输入的文本文件
- 如何打印混合 ASCII 字符和 Unicode 的字符串的每个字符
- 将 c++ 字符串与 c 混合
- 在VC ++浮点数据类型值中,如何检查字符串或特殊字符是否混合
- 我可以将编译时字符串比较与 MPL 模板混合使用吗?
- 检测混合字符串中的非字母字符
- C++正在混合我的字符串
- 在c++中逐行打印两个字符串的混合
- 在c++中从文件中读取字符串、整型和双精度的混合
- Yaml-cpp解析混合数组/字符串节点时出现问题
- c和c++混合编程中的字符串处理
- 增强:精神字符/字符串混合
- 在c++ /Qt中拆分Lua函数调用的混合字符串/数字参数列表
- Visual Studio 2010 上的C++:无法将字符串分配给字符串(不支持混合类型)
- RCDATA:混合字符串和二进制数据