Turning a sentence into numbers

Is it possible to turn a sentence into numbers where the number represents how many characters the word had.

Example: I went to the park today --- 1 4 2 3 4 5
Of course it's possible, you just demonstrated it.
Ya but I am not sure how to go about it in c++
operator>> already extract words from a stream, so I don't see the problem.
http://www.cplusplus.com/doc/tutorial/basic_io/
Something like this I guess.

Requires:
1
2
3
#include <iostream>
#include <string>
#include <sstream> 


1
2
3
4
5
6
7
8
9
std::string Line;                   // A container to hold a whole sentense
std::getline(std::cin, Line);       // Get the sentence from cin
std::stringstream iss(Line);        // Put the sentence back in a stream
while (iss.good())                  // Keep extracting words until the stream is empty
{  
  std::string word;                 // A container to hold individual words
  iss >> word;                      // extract the word
  std::cout << word.size() << ' ';  // print out the size of the word    
}
Topic archived. No new replies allowed.