The error says s
is undefined at this point in my code:
cout << "Enter the string : ";
cin >> s;
How can I fix that?
Also, another error at my second bracket says "expecting a ;". What can I do to fix that?
Here's my full code:
#include <stdafx.h>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main()
{
void permutation(string s, int i, int n)
{
int j;
if (i == n)
cout << s << "\t";
else
{
for (j = i; j < s.length(); j++)
{
swap(s[i], s[j]);
permutation(s, i + 1, n);
swap(s[i], s[j]);
cout << "Enter the string : ";
cin >> s;
cout << endl << "The permutations of the given string : " << endl;
permutation(s, 0, s.length() - 1);
cout << endl;
}
You have declared your function inside the main block, which is causing the compilation error. Declare it outside as-