J
J
jetkirill2021-06-17 06:28:33
C++ / C#
jetkirill, 2021-06-17 06:28:33

Why is the file not being read?

char simb;
    while (!fm.eof()) {
      fm.get(simb);
      cout << simb;
      rash.push_back(simb);
      
    }

Instead of writing a file to an array and reading it, it returns only empty characters (spaces).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-06-17
@jetkirill

The code you provided looks correct. It doesn't output what you want due to another error. For example, the file is empty but you manually check another file.
Either the file does not open because it does not exist, or you compile via C++98.
The documentation says (note after the parameters):

If the mode has both trunc and app set, the opening operation fails. It also fails if either is set but out is not, or if both app and in are set .

You, judging by the comments, open with app and in together.
Do you really need to read and write from this file, and even increase its size?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question