Loop: Compiles ok, crashes when run
Aim = count lines in the file Code within loop that crashes: _____________________________________ while (file.get(read)){ if (read=='\n') { cout << line_number << endl; line_number++; //when i try to increase line_number it compiles, however when i run the programm windows stops it. } ______________________ full function code: _______________________________ int convert_to_array (char *pFileName) { char read; string sRead; fstream file(pFileName,ios::in); int aLength,line_number; string array[aLength]; if (file.is_open()) { cout << "file again opened " << pFileName<<endl; line_number = 1; while (file.get(read)){ if (read=='\n') { cout << line_number << endl; line_number++; //when i try to increase line_number it compiles, however when i run the programm windows stops it. } sRead=sRead+read; cout << sRead << flush; sRead.clear(); } file.close(); } }