In Linux the output is printed correctly, with 'lines2' having the same value as 'lines' minus 1, but in windows the value of 'lines2' and is always printed as -2.
The source code is solely for testing purposes, hence the messy code with no for loops, bad variable names etc.
Apologies for posting about something fundamental as this (and posting a messy source code).
Any help is very much appreciated.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
main()
{
ifstream fis;
string str = "";
string filename;
int lines= -1;
int lines2 = -2;
cout << "Enter file: " << endl;
cin >> filename;
fis.open(filename.c_str());
while(!fis.eof())
{
lines++;
fis >> str;
}
fis.close();
cout << "Lines:" << lines;
fis.open(filename.c_str());
while(!fis.eof())
{
lines2++;
fis >> str;
}
fis.close();
cout << "Lines-1:" << lines2;
return 0;
}