+ 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!
+ 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 :)
+ 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😍😍
+ 5
The latter is stream optimized.. 🤔 C+out
Printf is a string dump IMHO 🙄
+ 4
C++ is not a subset of C. It's more of a superset.
+ 3
cout is not a function, so don't write it as cout() as you did in the question.
+ 3
Using endl with cout results in flushing the buffer but this does not automatically happen when you use \n with printf for example.
+ 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
+ 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 😅😅



