0

Why does c++ executive printf() function although it comes under c programming ?

Was programming with c++ and by mistake I wrote printf() and when excited it didn't show any error and succefully gave an output.

12th May 2021, 8:16 PM
Hari Om
Hari Om - avatar
5 Respuestas
+ 1
rkk From the link you shared: Translation: This is where the real advantage of printf lies. The printf format string is well... a string. That makes it really easy to translate, compared to operator << abuse of iostream. Assuming that the gettext() function translates, and you want to show Error 2: File not found., the code to get translation of the previously shown format string would look like this: printf(gettext("Error %d: %s.\n"), id, errors[id]); Now, let's assume that we translate to Fictionish, where the error number is after the description. The translated string would look like %2$s oru %1$d.\n. How would you do this with cout only?
12th May 2021, 10:06 PM
Michal Doruch
+ 2
Juan Pablo Segundo Sir can you pls elaborate more on what are the "things" that are possible with printf and not with cout? printf vs cout https://stackoverflow.com/questions/2872543/printf-vs-cout-in-c
12th May 2021, 9:15 PM
minirkk
minirkk - avatar
+ 1
Why wouldn't that work? Almost everything from C works in C++. You can use C libraries in C++, so there is no problem using printf, scanf etc. Some things are not even possible to do with cout, but you can do them using printf()
12th May 2021, 8:55 PM
Michal Doruch
0
Thank you Juan!
13th May 2021, 2:27 AM
Hari Om
Hari Om - avatar
0
c++ is the oo version of c with some extra features cin and cout have some extra flags that you can use for extra tricks like while (cin>>some_varible){} just to be able to validate the appropriate value for the data type printf and scanf does the work with less flags mainly used for compitive programming just to win this extra millisecond (it make difference in some case) or some just stop the cin and cout flags
13th May 2021, 7:17 AM
Michael George
Michael George - avatar