#include <string>
#include <iostream>
usingnamespace std;
void string_permutation(std::string& x, std::string& permute)
{
if(x.empty())
{
std::printf("%s \n", permute); <<<< other problem
return;
}
for(int i=0; i<x.size(); ++i)
{
std::string y = x;
y.erase(i,1);
std::string permute2 = permute;
permute2 += x.at(i);
string_permutation(y, permute2);
}
}
int main()
{
system ("color 0A");
string input;
printf("Enter permutation: ");
scanf("%s", input); <<<< here is the problem
std::string x = input;
std:string permute;
string_permutation(x, permute);
system("PAUSE");
return 0;
}
why won't it let me read the string properly? i don't understand why it just doesn't work.
Please don't tell me to use getline (cin, input); unless there's no other way. I have something against cin and cout.
Also while trying to actually printf my permutation i get the same problem.
Sorry if i seem like a total noob, i'm new to c++ :L
The C io functions (scanf, printf) take char arrays, not string objects. Since string objects do not exist in C.
The C++ versions (cin, cout) take string objects.
So if you want to use strings (which is good, they're useful and less error prone than char arrays), then it's best if you just bite the bullet and use cin/cout. I'm not crazy about iostream myself... it certainly has its share of problems... but don't needlessly shut it down. It's still a good tool.