Search notes:

C++ Standard Library: ostringstream - write formatted text into a char array in memory

ostringstream is to be the C++ replacement for sprintf.
ostringstream is the char specialization of the template class basic_ostringstream (that is, it is: std::basic_ostringstream<char>).
#include <sstream>
#include <iostream>
#include <string>

int main() {

  std::ostringstream oss;

  oss << "Hello, world" << std::endl;
  oss << "42" << std::endl;

  std::string str = oss.str();

  std::cout << str;

}
Github repository about-cpp-standard-library, path: /sstream/ostringstream.cpp

See also

C++ Standard Library

Index