can we use printf and scanf in C++ cause some guys just confused me
can we use printf and scanf in C++ cause some guys just confused me
You can, but in most cases it makes more sense to use the C++ equivalents.
but not necessarily when you want your input formatted in a certain way.
example: "mm/dd/yyyy"
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
The standard for C++ says that (essentially) any existing C code should still work as C++ code, so from that perspective, scanf/printf are valid C++ code.
Some would of course say that "then it's not proper C++", but that is a bit of a different topic.
However, there are some interesting limitations:
Both stdio FILE functions (e.g. stdin and stdout that is used implicitly in printf and scanf) and the C++ streams (e.g cin/cout) are allowed to buffer data. This means that if you MIX cin/cout with stdin/stdout operations, you may find stuff going wrong. There is a sync_with_stdio function that ensures that the different I/O mechanisms are in sync.
sync_with_stdio - C++ Reference
Note that since this involves implementation specific components, it may seem unnecessary to sync these things, and then you change the compiler (version or supplier), or compile the code for a different OS (or even turn off debugging), and it falls apart.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
As to formatting data with streams, boost has a nice formatting library for use with streams that outdoes printf formatting.