C++에서 printf랑 cout은 무슨 차이가 있나요?

Asked 2 years ago, Updated 2 years ago, 91 views

What is the difference between printf and cout in C++?

Well, printf has to use a separate format designator, so it's annoying...

What's the difference other than this?

c c++ printf cout

2022-09-22 14:34

1 Answers

printf is usually used in special situations because it is faster than cout C++ usually uses cout.

To summarize C++'s Why should I use inside of the traditional

Considering safety and error, scalability and inheritance, <iostream> is better than <cstdio>.

printf() and scanf() are also good features in themselves, but there are many restrictions for C++ I/O to see. The following is a comparison between C++ (<<, >>) and C (printf() and scanf()).

Type-safe: <iostream> provides a static indication of the type of object the compiler is I/Oing. Conversely, <cstdio> dynamically determines the type by using %.

Less error prone: <cstdio> writes % so the formatter must match the object that it is actually going to I/O. <iostream> can reduce errors because it does not write a %> token.

Extensible: <iostream> mechanism allows I/O of user-defined types without changing existing code.

Inheritable: <iostream> mechanism is created from real classes such as std::ostream or std:stream, so <cstio> inherits unlike FILE. So the things that you define look like streams, and they act like streams.


2022-09-22 14:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.