c++ - Counting number of even lines from file -


#include <iostream> #include <fstream> #include <string>  using namespace std;  int main() {      ifstream plik;      plik.open("napisy.txt");     int nr_line=0;     string line;     int ile_parzystych=0;       cout << "podpunkt a)=:"<< endl;      if(plik.good()==false){         cout << "wrong read of file!"<<endl;     }      while(getline(plik,line))     {         if( line.length() / 2 == 0)          {             ile_parzystych++;              if(nr_line==1)             {cout << "to jest pierrwsza linia - jest ona nieparzysta więc licznik = " << ile_parzystych << endl;}             if(nr_line==2)             {cout << "to jest druga linia - jest ona parzysta więc licznik = " << ile_parzystych << endl;}         }     }     plik.close();     cout << endl <<  ile_parzystych << " <- tyle jest linii parzystych";      } 

problem have output:

cout << "podpunkt a)=:"<< endl;

so it's shows podpunkt a)=:, and

cout << endl << ile_parzystych << " <- tyle jest linii parzystych"; 0 <- tyl jest linii parzystych

i don't know why it's not counting.

nr_line remains @ 0 whole program, loop never enter 2 if conditions

if (nr_line == 1) 

and

if (nr_line == 2) 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -