FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

str() method from fcf::NTest::TimeDuration class

std::string str(bool a_friendly = false) const

Class: fcf::NTest::TimeDuration

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Converts the duration to a string representation.

The str method converts the internal nanosecond value into a human-readable string format.

It supports two distinct modes:

  • Friendly Mode: When a_friendly is true, it returns a format with separators (e.g., 1.500`000`000). This is ideal for logs and user interfaces.
  • Raw Mode: When a_friendly is false, it returns a standard floating-point format with 9 decimal places (e.g., 1.500000000).

Arguments

bool a_friendly = false
- Whether to use the human-friendly format with separators.
Result
std::string
- A string representation of the duration.

Example: String formatting modes

Demonstrating the difference between friendly and raw string outputs.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("TimeDemo", "Basics", "StringFormatting") { fcf::NTest::TimeDuration duration(1234567890ULL); // 1. Get friendly string std::string friendly = duration.str(true); // 2. Get raw string std::string raw = duration.str(false); std::cout << "Friendly: " << friendly << std::endl; std::cout << "Raw: " << raw << std::endl; FCF_TEST(friendly == "1.234`567`890", friendly); FCF_TEST(raw == "1.234567890", raw); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "TimeDemo" -> "Basics" -> "StringFormatting" ... Friendly: 1.234`567`890 Raw: 1.234567890 [SUCCESS] Test completed successfully (0.000`000`000 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`000`000 sec