write after stock_name reading
if ( in.eof() )
    break;

because you add one more string to the output file.
run test in project solutions/ivan_sidarau/2 and use generated input_261.txt