c++ - Writing to a file duplicates the last entry -
i think lines of code needed. program reads text file, separates information out , rewrites 2 different files. "correctly" reads values, , separates appropriately. issue having, in files output duplicates last entry file. know how solve if using getline()
input, reading in each individual word separately in file.
here code think issue is:
while (in_file.peek() != eof) { in_file >> rank >> boy_name >> boy_number >> boy_percent >> girl_name >> girl_number >> girl_percent; boy_output << rank << " " << boy_name << " " << boy_percent << endl; girl_output << rank << " " << girl_name << " " << girl_percent << endl; }
i used while (getline(in_file, line) && in_file.peek() != eof)
in similar program, said reading information in line line, instead of word seperation.
thanks
you can try using -
while(1) { if(in_file.peek() == eof) { break; } in_file >> rank >> boy_name >> boy_number >> boy_percent >> girl_name >> girl_number >> girl_percent; boy_output << rank << " " << boy_name << " " << boy_percent << endl; girl_output << rank << " " << girl_name << " " << girl_percent << endl; }
Comments
Post a Comment