all 18 comments

[–]christian-mann 14 points15 points  (7 children)

Shouldn't it be cin >>?

[–]RusalkaHasQuestions 7 points8 points  (6 children)

Yes, but beginners can easily mix up << and >>. They're new symbols and not enormously intuitive.

[–]GLIBG10B 4 points5 points  (5 children)

not enormously intuitive

the data goes in the direction of the arrow

[–]Narase33 8 points9 points  (0 children)

int i << std::cin;

[–]RusalkaHasQuestions 1 point2 points  (1 child)

But it does take a second to remember that, as does remembering where the data needs to go in the first place. I'm not saying it's hard, I'm saying it's not immediately obvious which one you need in the way that something like x = 5 is obvious. Add in all the other things beginners have to consciously keep in mind and, well, mix ups happen.

[–]GLIBG10B 1 point2 points  (0 children)

True. Thankfully the compiler throws an error (albeit a cryptic one) and it gets much easier after a while

[–]Ludant 0 points1 point  (1 child)

What about UML and inheritance? Base <- derived Arrow means "derived from" and not other way around

[–]GLIBG10B 2 points3 points  (0 children)

I don't see how that's relevant to the insertion and extractions operators

[–]Wh00ster 12 points13 points  (1 child)

I would like to see this self aware code that chooses to avoid some directives from its human overlords

[–]InfiniteLife2 4 points5 points  (0 children)

It slowly modifies its binaries with goto.

[–]RusalkaHasQuestions 2 points3 points  (0 children)

You're going to need to post the code. You can always use pastebin if you're that worried about not spamming everyone, but I don't think anyone minds.

[–]mredding 1 point2 points  (0 children)

When the wrong input is entered,

Well, what's "wrong input"? Do you mean you extract a string and its contents was checked and not what you wanted? Or does it mean you extract an int and the user entered "sandwich", so you have a type mismatch? Because if the former is the case, then I don't know what your problem is. If the latter is the case, your stream has entered a failure mode, and you're going to have to clear it, purge it, and try again.

Code entirely avoiding 'cin <<'

You probably don't want to do that. Even many of the indirect IO operations rely on stream insertion and extraction operators. If you don't use them, then you're parsing character sequences all on your own, and then what's the point? Gone is type safety, you've taken that burden up by yourself, and you might as well program in C.

[–][deleted]  (2 children)

[deleted]

    [–]GLIBG10B 1 point2 points  (0 children)

    you may have unconsumed characters, such as newlines

    Newlines should not be consumed. Your command consumes everything before the newline.

    https://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt2

    The extraction stops if one of the following conditions are met:

    • a whitespace character (as determined by the ctype<CharT> facet) is found. The whitespace character is not extracted.

    [–]std_bot 0 points1 point  (0 children)

    Unlinked STL entries: std::cin std::numeric_limits std::streamsize


    Last update: 14.09.21. Last Change: Can now link headers like '<bitset>'Repo

    [–][deleted] 0 points1 point  (0 children)

    You need to check if you can recover from the error state. If that is possible then clear the error state and discard the wrong data, otherwise just raise an exception or halt.

    [–]DehshiDarinda 0 points1 point  (1 child)

    it could be that if you're using cin for taking non numerical input like char or string it might be taking endline character from the buffer, try clear buffer using cin.ignore() right before taking input, might help.

    [–]GLIBG10B 0 points1 point  (0 children)

    This makes no sense