fork download
  1. #include <random>
  2. #include <vector>
  3. #include <iostream>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7. int main()
  8. {
  9. std::random_device rd;
  10. std::mt19937 gen(rd());
  11. std::uniform_int_distribution<> dis(1, 9);
  12.  
  13. std::vector<int> array(5);
  14. std::generate(array.begin(), array.end(),
  15. [&](){ return dis(gen); });
  16. std::sort(array.begin(), array.end());
  17.  
  18. for (int i : array) {
  19. std::string str = "string" + std::to_string(i);
  20. std::cout << str << '\n';
  21. }
  22. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
string5
string6
string8
string9
string9