Need help with understanding

In the printf function I always see something like this
 
cout << printf("Enter what has to be done",1);


I understand the "Enter what has to be done" but I don't get the one. I always see this in rpg dialouge and what not what does it do?
I've never seen a ONE in printf before.
I've searched it in http://www.cplusplus.com/reference/cstdio/printf/ but the one was not there.
maybe give us the sample code?
@batijtha21 why did you just copy my whole statement?
closed account (48T7M4Gy)
cout << printf etc is incorrect.

The correct way to use printf is at http://www.cplusplus.com/reference/cstdio/printf/
cout << printf("Enter what has to be done",1);
This will display how many leters with space have this:
Enter what has to be done - there is 25
if you write Hello Word in printf it will display number 10
and so on....
closed account (48T7M4Gy)
Excellent! On my system it displays the number of characters and ignores the 1. So you can leave it out. Then you only problem is to find a uses for it. :)
It's not surprising, printf returns the numbers chars successfully written, though lots of people seem to forget there is a return value at all. People write printf("Hello World");

/Edit:

But they could have written:

int CharsWritten = printf("Hello World");

Edit/

The return value of printf can be important, especially if one writes to a file. In my C programming days (in a previous century) I would printf to a string (%s, aka array of char), if that worked I would fprintf the string to the file. Then the return value of that is checked as well, to see that it worked.

The 1 is a minimum width specifier, as per the documentation.

Another one is scanf, this one is more important - one should check the return value of this to see if it worked, it's easy to mess up the specification of what to read in, or more likely the input may not match the specification.

As kemort says, what is a valid use for this combination of std::cout and printf ?
Last edited on
Topic archived. No new replies allowed.