Hello. Faced a problem. Cannot split file.

void splitFile(string path) { int s = 0; char S[256]; int k = 10; string q[6] = {"a","b","c","d","e","f"}; int i = 0; ifstream in(path); while (!in.eof()) { fstream fout("xa" + q[i]); fout.seekg(0, ios_base::end); in.getline(S, 256); fout << S << "\n"; if (s = k) { s = 0; i++; } s++; fout.close(); } in.close(); } 

Tell me how to implement.

    1 answer 1

    At least replace

     if (s = k) 

    on

     if (s == k) 

    And yet - checking the while (!in.eof()) will upset you, because it will work only after unsuccessful reading, so the last reading is in.getline(S,256); will fail, and you will begin to ask why you have two identical lines at the end ...