1

I'm trying to pull text from a local directory. but why is it giving missing text? And when you say ok, the message box constantly pops up and shows other posts.

int LoadingSystem()
{
    std::ifstream myReadFile;
    myReadFile.open("resource/licence_english.txt");
    char output[10000];
    if (myReadFile.is_open())
    {
        while (!myReadFile.eof())
        {
        myReadFile >> output;
        MessageBox(NULL, output, "Test Message", MB_OK);
        }
        return 0;
    }
}

You can see the result from this picture.

drescherjm
  • 9,653
  • 5
  • 43
  • 62
Yusuf
  • 11
  • 2
  • The code shows the MessageBox for every word read. While reading it throws away the previous word read and reads a new word. Also the code reads until 1 read past the end of the file by incorrectly using eof(). – drescherjm Mar 06 '22 at 15:32
  • I assume you are tying to read the whole contents of the file into `output` buffer, not word-by-word as you are currently doing. Make it `myReadFile.read(output, sizeof(output)-1); output[myReadFile.gcount()] = 0;` – Igor Tandetnik Mar 06 '22 at 15:54
  • Does this answer your question? [How to read a file line by line or a whole text file at once?](https://stackoverflow.com/questions/13035674/how-to-read-a-file-line-by-line-or-a-whole-text-file-at-once) – Raymond Chen Apr 11 '22 at 13:56

0 Answers0