I have an array called "topboard" which reads data from "topboard.txt", but after reading it contains garbage values. In "topboard.txt" I keep top-10 scores from make Snake game, so "topboard.txt" looks like this (every score value should begin from new line): 560 470 300 ... And I need to put all of those values in my array on cpu. The code I wrote:
void stopGame() {
    gameOver = true;
    int topboard[11];
    // Writed last score in 11 line
    ofstream fileOutputStream;
    fileOutputStream.open("topboard.txt");
    fileOutputStream << endl << score;
    fileOutputStream.close();
    // read whole file to topboard[]
    ifstream inputFileStream;
    inputFileStream.open("topboard.txt");
    for (int i = 0; inputFileStream.eof(); i++) {
        inputFileStream >> topboard[i];
    }
    inputFileStream.close();
    
    // do some sorting stuff here
    // writed back new (sorted) topboard
    fileOutputStream.open("topboard.txt", ios_base::trunc);
    for (int i = 0; i < 10; i++) {
        fileOutputStream << topboard[i];
    }
    fileOutputStream.close();
};
And the output I have:
-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460
