#include <iostream>
#include <sstream>
void output_to_terminal()
{
std::cout << "this is a test" << std::endl; // simple output to terminal
}
void do_something_with_the_output(const std::string_view &sv)
{
std::cout << "there were " << sv.length() << " characters in the output" << std::endl;
}
void output_to_stream_then_terminal()
{
std::ostringstream strm; // an in-memory stream destination
strm << "this is a test"; // save the output in strm
do_something_with_the_output(strm.str()); // pass the output to somewhere
std::cout << "also printing it: " << strm.str() << std::endl; // actually put the output to the terminal
}
int main()
{
output_to_terminal();
output_to_stream_then_terminal();
}
To embed this project on your website, copy the following code and paste it into your website's HTML: