tags:

views:

75

answers:

2

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
+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
std::string hovewer has c_str()
dimba
@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