0

I was about to read a PNG file from stdin using the following code:

std::string input;
char ch;
std::cin >> std::noskipws;
while (!std::cin.eof())
{
    std::cin.get(ch);
    input += ch;
}

However, I could only get 5 bytes since PNG header contains a Ctrl-Z and stops reading.

What should I do to read the whole file?

1 Answers1

2

std::cin is opened in text mode and you need to read binary data.

Have a look at this question

Community
  • 1
  • 1
Gary
  • 5,642
  • 1
  • 21
  • 41
  • 1
    If the answers are so similar, why did you answer instead of you tagging it as a duplicate? This answer is basically a comment. – user4581301 Jan 12 '17 at 05:48