Program Not Reading Previous Words

I'm attempting to make a program that reads the number of lines, words, characters, unique words and unique characters. So far I've gotten everything correct except for the words and characters. The program just reads the words and characters of the last sentence inputted. Any help would be greatly appreciated.
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
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <set>
using std::set;
using namespace std;
// write this function to help you out with the computation.
unsigned long countWords(const string& s, set<string>& wl)
	{
		string x = " \t";
		unsigned long count = 0;
		size_t pos = -1, next = s.find_first_of(x);
		while (next != string::npos){
			if (pos +1 < next){
				++count;
				wl.insert(s.substr(pos+1,next-pos-1));
			}
			pos = next;
			next = s.find_first_of(x,next+1);
		}
	if (pos+1 < s.length()){
		++count;
		wl.insert(s.substr(pos+1));
	}
return count;
	}
int main(){
	cout << "Please Enter a couple of Words" << endl;
	string linecount;
	set<string> wordcount;
	set<string> linecount1;
	unsigned long lines = 0; // still not certain whats the point of "unsigned" only using it because its in the function above
	unsigned long words = 0;
	unsigned long charcount = 0;
	while(getline(cin,linecount)){
		++lines;
		words =+ countWords(linecount,wordcount);
		charcount =+ linecount.length()+1;
		linecount1.insert(linecount);
	}
	cout << "\t" << lines /*"Number of lines: " << lines*/ 
		 << "\t" << words//"Number of words: " << words << endl;
	     << "\t" << charcount // << "Number of characters: " << charcount << endl; 
		 << "\t" << linecount1.size()//"Unique lines: " << linecount1.size() << endl;
		 << "\t" << wordcount.size() << endl;//<< "Unique words: " << wordcount.size() << endl;

	return 0;
}
Topic archived. No new replies allowed.