Learning C++ in college right now, and for one project I had to write a program that lists all permutations of different names. The code works fine on repl.it, but on Zybooks(the website used for class) I get an error. What do I do?
#include <vector>
#include <string>
#include <iostream>
using namespace std;
void AllPermutations(vector<string> &permList, vector<string> &nameList) {
string tmpName;
int i;
if (permList.size() == 3){
for (i = 0; i < permList.size(); ++i){
cout << permList.at(i) << " ";}
cout << endl;
}
else {
for (i = 0; i < nameList.size(); ++i){
tmpName = nameList.at(i);
nameList.erase(nameList.begin() + i);
permList.push_back(tmpName);
AllPermutations(permList, nameList);
nameList.insert(nameList.begin() + i, tmpName);
permList.pop_back();
}
}
}
int main() {
vector<string> nameList(0);
vector<string> permList(0);
string name;
getline(cin,name);
while (name != "-1"){
nameList.push_back(name);
getline(cin,name);
}
AllPermutations(permList, nameList);
return 0;
}