xcode - C++ std::printf("%u", 5) adds a number after the expected output -
the output of following code 51 instead of expected 5. use xcode 6.4 llvm compiler on mac os yosemite 10.10.4.
#include <iostream> int main(int argc, const char * argv[]) { std::cout << std::printf("%u", 5) << std::endl; return 0; } if have tried supply int, unsigned long , uint32_t, , have swapped %u %d , %lu, same result: strange number being after intended printf output. swapping 5 number results in unexpected number being added output. in fresh project no other code added. overlooking?
printf returns int. in case returning 1 number of characters written (5).
cout printing 1, after printf prints 5 because you're chaining them together.
to 5, say:
std::printf("%u\n", 5)
Comments
Post a Comment