I have looked it up over the Internet. I have found many answers comparing cin
vs scanf()
and cout
vs printf()
, but never found if cin
actually uses scanf()
internally like new
operator in C++ uses malloc()
function of C.

- 2,705
- 5
- 23
- 60

- 105
- 2
- 9
-
`cin` and `cout` `std::istream` and `std::ostream` objects respectively, so your question is properly about how these *classes* are implemented. The simplest way to determine that is to build code using the `cin` and `cout` objects, and generate a linker map file and see what library symbols are linked. However I would say it is unlikely, the high-level functionality differs between the two. More likely that they converge at the lower level `fread()`/`fwrite()` or just `read()`/`write()` if at all. – Clifford Jul 11 '20 at 17:49
-
`new` on my platform has a separate heap manager from `malloc`, so they are independent. – Eljay Jul 11 '20 at 19:48
-
`std::cin` and `std::cout` don't call anything. They're objects. When you write `std::cout << "Hello, world\n"` the stream inserter (`operator<<`) does the work. – Pete Becker Jul 11 '20 at 20:24
-
Yes. I should have framed the question properly. I meant if the operator overloaded function calls printf or scanf – Charan Sai Jul 12 '20 at 12:02
2 Answers
The C++ standard does not specify how standard library facilities such as std::cin
and std::cout
are implemented, only how they should behave. Whether the C++ I/O functions call their C counterparts is up to the implementation.
As an example of how the C++ I/O streams can be implemented, we can look at the source code of libstdc++, which is GCC's standard library implementation. The std::basic_istream& operator>>(int&)
function which is the one called when you use std::cin >> x
to read an int calls some functions which call other functions and it eventually reaches this _M_extract_int
function that actually parses the integer. Therefore, libstdc++ does not implement the stream extraction operator for ints using C I/O functions. Still, remember that this is only one example and other standard library implementations may be different.

- 4,626
- 4
- 16
- 34
C++ standard specifies what objects std::cout
and std::cin
must do. How it is implemented depends on vendor.
The best way to be sure is to read the source code of given implementation.
You also need to know, that under the hood printf()
uses also other functions. It would be optimization wise to implement cout
with them, as this object doesn't work exactly as printf()
function.
There is also a little to no chance of std::cin
using scanf()
, as it tends to be problematic (read more on A beginners' guide away from scanf()
).

- 2,705
- 5
- 23
- 60