printf
is a C function, not a C++ one, if you are learning C++ you should try to solve the problem with std::cout
, which is the usual way of printing.
Anyway, printf
is pretty simple to use, it takes a first argument that is a string (a C string, so an array of char with the last char as a '\0'
character) and as many parameters as you have format specifiers in your string (a format specifiers is a %
char followed by another char that the function what time the variable is going to be)
Examples:
int intvat;
char charvar;
float floatvar;
char* stringvar; // to print it the last char of stringvar must be \0
printf("this is an int: %d", intvar);
printf("this is a char: %c", charvar);
printf("this is a string: %s", stringvar);
printf("this is a float and an int: %f, %d", floatvar, intvar);
For more information about printf you can refer to the reference page here: http://www.cplusplus.com/reference/cstdio/printf/
– user Mar 04 '17 at 16:16