sort() function not working.

So I thought that the sort() function was included with the algorithm preprocessor directive (#include <algorithm>) but as I use sort, it doesn't work. Here's my code where I tested it out.


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
 #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	vector<string> words;
	for (string temp; cin >> temp;)
	{
		words.push_back(temp);
	}
		cout << "Number of Words : " << words.size() << "\n";

	sort(words);

	for (int i = 0; i < words.size(); ++i)
	{
		if (i == 0 || words[i - 1] != words[i])
		{
			cout << words[i] << "\n" << endl;

		}


	}


	system("PAUSE");
	return 0;
}

http://www.cplusplus.com/reference/algorithm/sort/
check out the prototype for std::sort
Topic archived. No new replies allowed.