6

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?

3
  • If you know your platform, you could try to reopen stdin using an ifstream (the point I can't do it in a portable way, /dev/stdin should work for -ixes), then use rdbuf to hook that into std::cin. Commented Jul 29, 2012 at 23:11
  • See also stackoverflow.com/questions/7587595/… Commented Jul 29, 2012 at 23:13
  • Also see the discussion of using std::freopen (but it looks kind of hacky). It would be nice if someone provided a canonical answer with examples for BSDs, Linux, OS X, Solaris and Windows. Commented May 20, 2018 at 18:27

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I think the problem is, std::cin is opened in text mode. There may be some unwanted translations due to text mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.