how to find repeated words

I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.
does no one have any suggestions?
You might begin with code that compares one word to another.
I'm having trouble creating code that lets the program know when and where each word starts and ends.
Then perhaps you should begin with code that simply counts the number of words in a string. How do you decide where the words begin and end?
I tried using an iterator to find each character in the string that was a space and indicating that this is the start of a new word and the end of the word just processed. But I kept getting syntactical errors. Not really my strong point.
iebwen (9)
I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.

We don't know what you are taught previously. So we cannot solve your homework for you.
I had a project that parsed and wrote pickit files for a bot... and for that I generally loaded each word into a string, each string in a line into a vector of strings, and each line of vectored strings into a multidimensional array (vector<vector<string>>). Spaces weren't loaded because file loading considers spaces as separators between inputs.

That said, there were lines with irrelevant data, and lines with spaces that could cause issue while parsing, and using exclusion keys, string searches and replacements I was able to filter out my problems.

example :
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
ifstream("myfilename.dat");
string line;
vector<vector<string>> vv;
string key1 = " ";

for (std::string line; std::getline(file, line); vv.push_back(std::vector<string> std::istream_iterator<string>(stay(std::istringstream(line))),
std::istream_iterator<string>()) ) ) 

{
                if(line.empty())
	        {
			line = "//";
		}
		if(line == tempstr)
		{
			line = "//";
		}
}

int fsize = vv.size();

for(int i = 0; i < vv.size(); i++)
{
        string var = "//";
	if(vv[i][0].find(var) != string::npos)
	{
		fsize--;
	}
}


just an example, similar to what you're tryig to do.
Topic archived. No new replies allowed.