I am reading the lines form the file and 'len' is returning the length
of each line.Now the problem is if i am not wrong windows uses carriage
return followed by a line feed to mark the end of the line. so for each
line 'len' should return be two extra characters ex. if i have file
gillian
dave
robby
so for gillian --it should return len 9(including \r\n according to
windows)
but the following function is returning 8. Is there anything wrong the
way i am doing it.
#include <fstream>
#include <istream>
#include <iostream>
#include <ostream>
#include <string>
using namespace std;
void omit(istream& in, ostream& out, const string s)
{
static string line;
int len;
while(getline(in,line))
{
len=line.length();
cout<<line<<endl;
cout<<len<<endl;
}
}
int main()
{
const string in_name("example.txt");
const string out_name("test.txt");
ifstream input(in_name.c_str());
ofstream output(out_name.c_str());
if(!input)
cerr << "Cannot open input\n";
if(!output)
cerr << "Cannot open output\n";
if(input && output)
omit(input, output, "raka");
if(!input.eof())
cerr << "Error reading input\n";
if(!output)
cerr << "Error writing output\n";
return 0;
}