Is there're way to pass boost::tuple to printf()?
Asked
Active
Viewed 858 times
2 Answers
3
Not directly, because printf
requires certain format specifiers. You'd need to print each element out at a time.
You might make a template function that iterates over the elements of the tuple, printing them out. This question address that. That said, that again won't work unless each element can be printed out with printf
.
Rather, why not use iostream
instead? Then you can just say std::cout << theTuple
.
1
No, because "printf" is a C function and has no idea how to handle C++ objects. That said, if all you want to do is create a formatted message, you might want to check out The Boost Format Library.

Michael Aaron Safyan
- 93,612
- 16
- 138
- 200
-
std::string hovewer has c_str() – dimba Dec 07 '09 at 05:03
-
@idimba,... and? The result of c_str() is const char*. You cannot pass an object of type std::string directly to printf. – Michael Aaron Safyan Dec 07 '09 at 08:58