Q:

Is there a way to generate output as a list in C++?

I am a beginner in C++. I am trying to generate different permutations of a string as shown in the code below. However, due to my need for certain downstream processes where member functions of a list will fit the most, I am wondering if there is a possibility of generating all the permutations as different elements in the list. Thereafter, I can use the list with other member functions. I have been trying and so far, I have only managed to assign each permutation individually to the list and output it with every iteration of the loop. However, I want to generate only one list at the end of all the iterations. I am aware that I need to take it out of the loops and I have tried but I was unable to call on outputlist outside of the function.
#include <iostream>
#include <math.h>
#include <list
using namespace std;

void createList(string item) {
     list<string> outputlist; 
     outputlist.push_back(item);
     cout << "The output list is: " << endl; 
          for(list<string>::iterator iter=outputlist.begin(); iter!=outputlist.end(); iter++) {
          cout << *iter << endl; 
          }
} 

void permutations(string str, int i, int n) {
     if(i == n-1) {
       createList(str);
     } 
     for (int j = i; j < n; j++) {
         swap(str[i], str[j]); 
         permutations(str, i+1, n); 
         swap(str[i], str[j]); 
     }
}

A:

Your list is local, and you never return it.
In your case taking by output parameter allow easy modification inside recursive function:
void permutations(std::string str, int i, int n, std::list<std::string>& output) {
     if(i == n-1) {
       output.push_back(str);
     }
     for (int j = i; j < n; j++) {
         std::swap(str[i], str[j]); 
         permutations(str, i+1, n, output); 
         std::swap(str[i], str[j]); 
     }
}

To simplify the call, I suggest to add
std::list<std::string> permutations(const std::string& str) {
    std::list<std::string> res;

    permutations(str, 0, str.size(), res);
    return res;
}

and so your main might be:
int main()
{
    for (const auto& s : permutations("hello world")) {
        std::cout << s << std::endl;
    }
}

Demo
Notice that std provide std::next_permutation, so I will do:
std::vector<std::string> permutations(std::string s)
{
    std::vector<std::string> res;

    std::sort(s.begin(), s.end());
    do {
        res.push_back(s);
    } while (std::next_permutation(s.begin(), s.end()));

    return res;
}

Demo
Notice the difference of results (except the order), std::next_permutation doesn't have duplicate output when input has duplicate letters.

