I know that std::cout is the C++ equivalent of printf.
std::cout
printf
What is the C++ equivalent of sprintf?
sprintf
std::ostringstream
Example:
#include <iostream> #include <sstream> // for ostringstream #include <string> int main() { std::string name = "nemo"; int age = 1000; std::ostringstream out; out << "name: " << name << ", age: " << age; std::cout << out.str() << ' '; return 0; }
Output:
name: nemo, age: 1000
2.1m questions
2.1m answers
60 comments
57.0k users