+ 10
Below is a case where printf is far superior to cout. In the Code Coach topic Military Time, my C code looked like this: printf("%02d:%02d", hr, mm); And my C++ code looked like this: cout << setfill('0') << setw(2) << hr          << colon          << setfill('0') << setw(2) << mm; Ugly! So in the C++ solution I included <stdio.h> and replaced the cout with printf. It worked fine!
4th Nov 2020, 10:26 AM
Brian
Brian - avatar
+ 9
Printf is actually more flexible than cout for formatting but also more complicated sometimes. The benefit of cout is that it (usually) detects the data type automatically, which can help prevent bugs and makes it a little bit easier. Also cout works better with OOP. Btw. the print! macro of the Rust programming language combines both advantages :)
4th Nov 2020, 7:28 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 5
Both printf(); and cout<<""; works in cpp We can print something to our output console by using any one of them As we are professional cpp programmers 🤣we have to use cout<<""; we can also mix cout and printf as your printing partners in your code😍😍
5th Nov 2020, 8:55 AM
VAMSI
VAMSI - avatar
+ 5
The latter is stream optimized.. 🤔 C+out Printf is a string dump IMHO 🙄
6th Nov 2020, 4:24 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 4
C++ is not a subset of C. It's more of a superset.
5th Nov 2020, 7:16 PM
Sonic
Sonic - avatar
+ 3
cout is not a function, so don't write it as cout() as you did in the question.
5th Nov 2020, 7:15 PM
Sonic
Sonic - avatar
+ 3
Using endl with cout results in flushing the buffer but this does not automatically happen when you use \n with printf for example.
5th Nov 2020, 7:18 PM
Sonic
Sonic - avatar
+ 2
That is simple. I had made a code that mixes both so you could use everything of C in C++. Here it is https://code.sololearn.com/cIpWWm6JB6pJ/?ref=app
4th Nov 2020, 3:00 PM
Aradhay Mathur
Aradhay Mathur - avatar
+ 2
BeegCat I think that printf syntax is simple and related to many languages and if you learn another language you will see similar syntax. But as everything has some bad things printf also have some but you have to google them as I dont know them 😅😅
4th Nov 2020, 3:14 PM
Aradhay Mathur
Aradhay Mathur - avatar