Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from standard in using ios::binary

I'm trying to read from standard input and distinguish each character from one another by its decimal value. From what I understand, a Line Feed (10) and a Carriage Return (13) will be interpreted as the same character. I want to distinguish between the two. I know if I was reading from a file I could open it using the ios::binary parameter. But what about if I am reading from standard input?

like image 815
ordinary Avatar asked Jul 29 '12 23:07

ordinary


People also ask

What does ios :: binary mean?

ios::binary means you want to open a file in the binary mode for input/output (when the file contains binary data) Refer to this for detailed expl. They are file modes in C++. ios::out means you want to open a file in the output mode (for writing data to a file)

How do I read a binary file in CPP?

To read a binary file in C++ use read method. It extracts a given number of bytes from the given stream and place them into the memory, pointed to by the first parameter. If any error is occurred during reading in the file, the stream is placed in an error state, all future read operation will be failed then.


1 Answers

You can read from std::cin by using get. This method is specially designed for reading unformatted data (see doc)

like image 166
Ivan Kruglov Avatar answered Oct 05 '22 10:10

Ivan Kruglov