Question about cin.get

Other than the fact that cin.get can read the enter key as an input whereas the regular cin can't, what's cin.get's purpose? Is that the only reason it was created? (so the enter key could be read as an input)
cin.get() is for reading "unformatted" input. So it just reads an exact amount of bytes from the file as is for you to handle. The extraction operator >> reads "formatted" input, which means doing a bit of intrepreting the data for you; here, it reads until whitespace, which naturally assumes you want to interpret each byte as a character with the ASCII meanings.

Basically, its a difference between formatted and unformatted input, which either says "read the data into a different type I ask for" (e.g., taking the characters '1' '2' and '3' in a row from the user as an integer 123) or "read the data as is" which gets the you bytes as characters.
Oh so like one is used if you want the computer to cin the number 123 as a string sorta speak and the other is if you want it to cin 123 as an integer? If so, which is which?
This example is for std::cout, not std::cin but it's still relevant. The formatted output/input reads "naturally". The unformatted input/output is raw data.

1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
    const int i = 1000;

    std::cout << i << '\n';
    std::cout.write(reinterpret_cast<const char *> (&i), sizeof i);
    std::cout << std::endl;
}
1000
č  

Topic archived. No new replies allowed.