A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/fmtlib/fmt/issues/2354 below:

GitHub ยท Where software is built

I noticed fmt::output_file() returns a special fmt::ostream. It'd be nice if there was something similar for printing to the screen (cout stream replacement) / building into a string (ostringstream replacement).

Then we could do something like this:

void build_text(fmt::ostream& stream)
{
  stream.print("Hello {}\n", "world");
  stream.print('foobar");
}

// Doesn't matter how you call it!

void to_console()
{
  auto stream = fmt::print();  // no argument overload?  or alternative console_stream();
  build_text(stream);
}

void to_file()
{
  auto stream = fmt::output_file("myfile");
  build_text(stream);
}

void to_string()
{
  auto stream = fmt::string_stream();
  build_text(stream);

  // to text!
  const std::string text = fmt::to_string(stream);
}

at the moment I think we have to fall back to stl streams in order to do this? But I thought those were slow in practice.

Please let me know if there's something I'm missing!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4