A beautiful and easy way of permutation with recursion
The simpler code would look something like this:

#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;

int main() {
    std::string s = "abcde";

    while (std::next_permutation(s.begin(), s.end()))
        std::cout &lt;&lt; s &lt;&lt; "\n";
}


If you wanted to do something on the same general order as a Python generator, you'd use C++'s new coroutine support. What's currently included is (by intent) very low-level, so you need a fair amount of infrastructure on top of it before it's easy to write a Python-like generator.

To keep from getting buried in details you probably don't care a lot about (right now) I'll use Kenny Kerr's Generator class (the first 173 lines, transplanted into a header). Using it, we get something like this:

#include "generator.hpp"
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

template &lt;class T&gt;
generator&lt;T&gt; perm(T initial) {
    while (std::next_permutation(initial.begin(), initial.end()))
        co_yield initial;
}

int main() { 
    using namespace std::literals;
    for (auto const &amp;i : perm("abcde"s))
        std::cout &lt;&lt; i &lt;&lt; "\n";
}


As to your code, a few points jump out:


Don't use std::endl. It flushes the stream, which you almost never want. Just use '\n'. On the rare occasion that you do want to flush the stream, use std::flush.
The C library reserves most names that start with str, so it's probably better to avoid using that as a name.
using namespace std; is widely considered a problem except under a small number of rather unusual circumstances.
If you really want to do this (more) on your own, you might want to take a look at std::rotate, which can replace both your swap2 and swap3. std::rotate will also typically be more efficient than your implementation.
swap2 and swap3 strike me as poor names. At first glance, it seems like rotate_left and rotate_right would probably be better names (but also see above).