Permutation issue

Some errors... please help.
What I am trying to do is reading an array of characters from a file (only latin characters, and less than 100) and check whether there is any possible next permutation in lexicographical order or not. If there is, print it out in a file, else just print a message.

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
33
34
35
36
37
38
39
#include <fstream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	vector<char> array;
	array.reserve(100);
	
	int L;
	
	ifstream in("code.in");
	ofstream out("code.out");
	
	while(in)
	{
		array.push_back(L);
	}
	
	if ( next_permutation(array) )
	{
		vector<char>::iterator character;
		
		for(character = array.begin(); character != array.end; ++character)
		{
			out << *character << " ";
		}
	}
	else
	{
		out << "This is the last code.";
	}
	
	in.close();
	out.close();
	
	return 0;
}


Errors:

Compiling source file(s)...
CI.cpp
CI.cpp: In function `int main(int, char**)':
CI.cpp:21: error: no matching function for call to `next_permutation(std::vector<char, std::allocator<char> >&)'
CI.cpp:25: error: no match for 'operator!=' in 'character != array.std::vector<_Tp, _Alloc>::end [with _Tp = char, _Alloc = std::allocator<char>]'


EDIT: Thanks, it works now.
Last edited on
CI.cpp:21: error: no matching function for call to `next_permutation(std::vector<char, std::allocator<char> >&)'


Where is your definition of next_permutation()?
The compiler can't compile a function call, if it doesn't know how to call it.

CI.cpp:25: error: no match for 'operator!=' in 'character != array.std::vector<_Tp, _Alloc>::end [with _Tp = char, _Alloc = std::allocator<char>]'


array.end must be a function call.
 
for(character = array.begin(); character != array.end(); ++character)



Sorry, couldn't access the forum for several hours after I tried to submit a reply. As Abstract noted, you are missing those ()'s. Also, it should be next_permutation(array.begin(),array.end());
AbstractionAnon wrote:
Where is your definition of next_permutation()?

LOL!!!
http://www.cplusplus.com/reference/algorithm/next_permutation/
OP is still missing the declaration, even if it's in <algorithm>, which isn't included.
Last edited on
Topic archived. No new replies allowed.