sorting word a loot

So i have this challenge atm.

Write a small program that can take a string:
"hi!"
and print all the possible permutations of the string:
"hi!"
"ih!"
"!hi"
"h!i"
"i!h"
etc...

Where should I begin?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include <algorithm>    // std::next_permutation

int main()
{
  std::string input;

  std::cout << "Enter string: ";
  std::getline(std::cin, input);
  std::sort(input.begin(), input.end()); // for some reason necessary

  do 
  {
    std::cout << input << '\n';
  } while (std::next_permutation(input.begin(), input.end()));

  return 0;
}


Output:
1
2
3
4
5
6
7
Enter string: hi!
!hi
!ih
h!i
hi!
i!h
ih!
Big thanks to you guys. I have one question why do some people use std:: and others do not. ( I do know that you can be using namespace std;)
if you use the std:: , your code will be more readable and everything will be clear.
You can write std:: and using namespace std; together. It will not be cause any errors. But when you didn't write using namespace std;, it is necessary to write std:: .
Topic archived. No new replies allowed.