|
-
Jan 21st, 2005, 10:12 AM
#1
Thread Starter
Frenzied Member
A question about printf.
I hardly know anything about C++ or C, but, there is one thing I was asking myself:
Apparently there is a function called printf in C++ which appears to be similair to the Print method in Visual Basic. In C++ source code I found while searching the internet and these forums I see symbols such as %ld, %s, %d and %u in the string passed to the printf function. What do these symbols do (if anything) when used with the printf function?
If you want to know why I am asking this if I don't really know and don't use C++, read this thread: http://vbforums.com/showthread.php?p...81#post1894281
Last edited by Peter Swinkels; Jan 21st, 2005 at 10:18 AM.
-
Jan 21st, 2005, 11:48 AM
#2
Fanatic Member
Re: A question about printf.
The symbols are format-specifiers. The first argument to printf is a format string which contains information on how printf should process/format the other arguments.
e.g.
int x = 5;
printf("%d", x); //tell printf that the first argument is a decimal/integer(%d), and pass x to be printed.
Or:
char* s = "hello";
int x = 5;
printf("%s %d", s, x); //prints "hello 5".
The most common specifiers are %s (string), %d (or %i, same thing) (integer), %f (float). There's more, and you can specify other things like precision. A C standard library reference will give you more info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|