Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

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

3 Answers

0 votes
answered May 31, 2020 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, 2020 by Peter Minarik (84,720 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.

References:

  1. http://www.cplusplus.com/reference/cstdio/printf/
  2. http://www.cplusplus.com/reference/iostream/cout/
  3. http://www.cplusplus.com/reference/ostream/ostream/
  4. http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
0 votes
answered Jun 5, 2020 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.
...