Help? Program to find words in text

Hey guys :)
I'm a beginner with C++ and there's this class that I'm taking, for beginners, but the professor is a bit crazy and he's giving us pretty difficult tasks. I'm kinda risking failing, so that's why he gave me this assignment that I can't wrap my head around :(
He says there is this text, and we have to create a program that chooses each individual word in the text and displays each word separately, together with the line of text it is found on. And each word is shown only once, from the first line it's found on. For example:

Text:
Hi guys my name is
Simona and my cat's name
is Snickers.

Output:
Hi 1
guys 1
my 1
name 1
is 1
Simona 2
and 2
cat's 2
Snickers 3

Any help would be much appreciated :) I'm really in a pickle here, and I know asking for your help is practically cheating, but I'm desperate :(

Thankies!
You can use std::getline to read in an entire line into a std::string, then you can make a std::istringstream from the string and extract each word with >>. You will need to nest loops - the oter loop will grab line-by-line, and the inner-loop will grab word-by-word. Just use the loop indices to know which line number you are on.
Topic archived. No new replies allowed.