I am trying to use sort defined in algorithm in c++. I want to use it in vector string ( vector<string> vec) can we use it i vector string.

here is my code


using namespace std;

int main()
	vector<string> vec;
	vector<string> ::iterator it;
	string s;
	char b[5];
	char a[5] = {'t','a','n','k','a'};
	int l=strlen(a);
	s = a; 
	for(int k=0;k<3;k++){
	for(int i=0;i<5;i++){
			b[i] = a[4];
			b[i] = a[i-1];
	for(int j=0;j<5;j++)
		a[j] = b[j];	
	for(int j=0;j<5;j++)
		s[j] = b[j];
	for(it = vec.begin();it!=vec.end();it++)

	return 0;

i wanted to generate different combination of 'tanka'

line 16: variable a is NOT a string but just an array of characters because it is not null terminated. So string functions such as strlen() (line 18) and cout (line 29)will not work with it. To use strlen() you should have declared it like this: char a[] = "tanka"; array b also needs to be increased by 1 to hold the null terminator character and it should be declared like this: char b[6] = {0}; line 20: array b doesn't contain anything at that point so why are you adding it to the vector? And since b has not been initialized to anything it will cause the vector a lot of problems, possibly even crashing your program.

This article has been dead for over six months. Start a new discussion instead.