basically i just need help with an algorithm this is just a snippet of my code i need to split a entire line of data. Assuming that this line is just a bunch of words seperated by a space. i need to get each line the display each word and the amount of chars in that word on its own line. My problem is how do i separate each word. I currently look for the space in between two words. reassign that into its own string then count the chars in it . How do i do find and reassign the last last word in the string as it does not have a space (' ') , it ends with a New line char.
string line,temp;
int letters; // how many letters
int words // how many total words
getline(ins, line);
ins.ignore(100, NWLN);
while (!ins.eof())
{
do
{
temp.assign(line, 0, line.find(' '));
line.erase(0, temp.length());
for (int i = 0; i < temp.length(); i++)
{
letters++;
}
words++;
outs << temp << " " << letters << endl;
} while (line.length() != NWLN);
getline(ins, line);