Expected a decleration

I have found this program for combination. But i am havig "expected a decleration" error. what am i missing?

#include<iostream>
#include<algorithm>
using namespace std;

void perm(string s, string t);
{
if (s.lenght() == 0)
{
cout << t << endl;
return 0;
}
for (int i = 0, i < s.lenght(); i++);
{
string s2 = s;
string t2 = t;
s2.erase(i, 1);
t2 += s[i];
perm(s2, t2);
}
}
int main()
{
string s = "xyz";
string t;
perm(s, t);

return 0;
}


Errors;
expected a decleration line: 6
'{': missing function header (old-style formal list?) line :6
To clear that first error the ; at the end of void perm(string s, string t); needs to be removed. You'll probably see a few more errors after that one gets cleared.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<algorithm>
using namespace std;

void perm(string s, string t);
{
    if (s.lenght() == 0)
    {
        cout << t << endl;
        return 0;
    }
    for (int i = 0, i < s.lenght(); i++);
    {
        string s2 = s;
        string t2 = t;
        s2.erase(i, 1);
        t2 += s[i];
        perm(s2, t2);
    }
}

int main()
{
    string s = "xyz";
    string t;
    perm(s, t);
    
    return 0;
}
Thank you it will help a lot.
Fixed without changing what you want the code to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <algorithm>

using namespace std;

void perm(string s, string t)
{
	if (s.length() == 0)
	{
		cout << t << endl;
	}
	else
	{
		for (int i = 0; i < s.length(); i++)
		{
			string s2 = s;
			string t2 = t;
			s2.erase(i, 1);
			t2 += s[i];
			perm(s2, t2);
		}
	}
}

int main()
{
	string s = "xyz";
	string t;
	perm(s, t);

	return 0;
}
Last edited on
Topic archived. No new replies allowed.