为什么"fin >> baff"
会更改"res"
???
char res[10000], buff[9];
int end, pos = 0;
ifstream fin( "input.txt");
fin.seekg( 0, ios::end);
end = (fin.tellg() / 8) - ( (fin.tellg() % 8 == 0) ? 0 : 1);
refresh( fin );
while( pos < end ){
fin.seekg( pos*8, ios::beg);
// this strange fin change my array res
fin >> buff;
refresh( fin );
if ( buff[3] == '1') {
if( buff[7] == '1') {
res[pos++] = '1';
} else if ( buff[7] == '0') {
res[pos++] = '0';
} else
cout << "Error1" << endl;
} else if ( buff[3] == '0') {
res[pos++] = ' ';
} else
cout << "Error2";
buff[8] = '\0';
cout << buff << " " << pos << endl;
}
cout << "End of game" << endl;
ofstream fout("result.txt");
for ( int i = 0; i < pos; ++i)
fout << res[i];
for ( int i = 0; i < pos; ++i)
cout << res[i];
当我调试此代码时,在3次迭代中,“ fin >> buf”更改了数组“ res”,这很奇怪。 对不起,我的英语。