Can I use scanf and printf in C ++?
Closed due to the fact that the essence of the question is not clear to the participants of Xander , Stranger in the Q , German Borisov , LFC , aleksandr barakin 12 Apr at 13:39 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- 6Yes You can. - Harry
- oneThe question in some sense sounds like a joke "Doctor, can I play the violin after the operation?" - AnT
- Yes, you will laugh;) - Zars.Stars
2 answers
According to the C ++ standard (C ++ 17, 20.2 The C standard library)
The C ++ standard library also makes it possible to use it.
and (20.5.1.2 Headers)
3 The standard library are provided in the additional headers shown in Table 17
in which (that is, in the table) the header <cstdio>
is also indicated, which contains, in particular, the scanf
and printf
functions.
And further
It is noted that it was through the use of the document. In the C ++ standard library, however, the declarations should be included within the namespace scope (6.3.6) of the namespace std. It is unspecified whether these names are given through through the use of a global law (10.3.3).
The latter means that C-functions are not necessarily placed in the global namespace. From this it follows that if you do not use the using-directive in your program
using namespace std;
then the program with reference to these functions will be structurally as follows:
#include <cstdio> // ... int main() { // ... std::printf( "Hello %s\n", "Zars.Stars" ); // ... }
That is, in the general case you should include the <cstdio>
header and use qualified names like std::printf
.
Yes. Here is an example:
/* scanf printf example */ #include <stdio.h> int main () { char str [80]; printf ("Enter your name: "); scanf ("%79s",str); printf ("Hello, %s.\n",str); return 0; }
- oneBut probably it is better to use
<cstdio>
. - HolyBlackCat