outputting number of alphabetical letters per line

hey guys i seariously need ur help asap ihve posted this problem before but couldnt quite get it....i want to calculate the number of letters in each line...my code takes a sentence and splits it into sub sentances after white-space....e.g "am so cold" should output the following: "am
so
cold"
and stores it in a vector...all that is all set and done but in want to count the letters in each line so from the above example the following output should be:2
2
4
thanx in advance.......am a newbie at this and strings are killing me...
trying to use a counter but its not working and my code is crusshing


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
 
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iterator>

using namespace std;

int main()
{
    ifstream infile("input.txt");
    string line;
    string buf;


    vector<string> tokens; // Create vector to hold our words
while(getline(infile,line))
{
    istringstream ss(line);
    while (ss >> buf)
        tokens.push_back(buf);

}
int counter=0;

//////////////////////////
for(counter=0;tokens[counter]!="\n";counter++)
{
  cout<<counter<<endl;
}
that was the first thing i did but still my out was not guving results per line....any ideas plz
Perhaps you should show that "first thing" that you did.
1
2
3
4
for ( auto word : tokens )
{
  std::cout << word << '-' << word.size() << '\n';
}
Topic archived. No new replies allowed.