Hi people, I am trying to read a text file and count each words length.
I have got these 2 things working, but I can't write the wordLength into text file.
anyone can help me out. thanks a lot~~
there is the text file like:
-------------
absent
absolute
absolutely
absorb
abstract
------------
then I need to make the text file like
-----------
absent,5
absolute,8
absolutely,10
absorb ,6
abstract,8
------------
here is the code:
---------------------
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
ifstream infile("words.txt");
while ( getline(infile, line) )
{
cout << line<<",";
string str(line);
cout <<str.length() <<endl;
}
return 0;
}
---------------------