Is there're way to pass boost::tuple to printf()?
+3
A:
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
.
GMan
2009-12-06 19:33:25
+1
A:
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
2009-12-06 19:34:17
std::string hovewer has c_str()
dimba
2009-12-07 05:03:52
@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
2009-12-07 08:58:49