In c ++ what's different between using ( printf) and (cout)?

+4 votes
asked May 31 by Abdallah Ahmed (170 points)

3 Answers

0 votes
answered May 31 by JAIPRASATH M (140 points)
cout is a output stream but printf is a function.

printf can be used for  both c and c++. but cout is only for c++.
0 votes
answered Jun 1 by Peter Minarik (7,040 points)

First of all printf() is a C method while cout is a C++ object (an ostream -- output stream), where you can use the "insertion operator" (<<) to write content to the stream.

In a C++ code, I'd suggest using the C++ way of writing to the output over the C way (which also works).

For more details, please see below.


0 votes
answered Jun 5 by Amar Kulkarni (180 points)

The difference is as follows:

1] printf() is a function, whereas cout ios an object of class ostream.

2] printf() cannot be used to print user-defined variables, whereas using cout we can by using operator overloading concept.

3]printf() requires format specifier, whereas cout does not require format specifier.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.