I know that std::cout
is the C++ equivalent of printf
.
What is the C++ equivalent of sprintf
?
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() << '\n';
return 0;
}
Output:
name: nemo, age: 1000