I am making a simple program to find out the number of lines not starting with a using file handling. I am not able to understand why my loop is only running 4 times when it should clearly run 0 through 1 less than value of lines. What is the problem here?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int s = 80;
char str[s];
int lines = 0, a = 0, alines = 0;
ofstream fout("file6.txt", ios::out);
cout<<"Enter the number of lines you want to enter: ";
cin>>lines;
for(int i = 0; i < lines; i++)
{
cin.getline(str, 80);
fout<<str<<endl;
}
return 0;
}