std::ostringstream builds a formatted string before sending it somewhere else.

Stringstream Formatting

stringstream_formatting.cpp
#include <iostream>
#include <sstream>
#include <string>

int main() {
    int quantity = ;
    int unitPrice = 4;

    std::ostringstream builder;
    builder << "items=" << quantity;
    builder << ",total=" << quantity * unitPrice;

    std::string receipt = builder.str();

    std::cout << receipt << std::endl;
    std::cout << "length=" << receipt.size() << std::endl;
    return 0;
}
#include <iostream>
#include <sstream>
#include <string>

int main() {
    int quantity = ;
    int unitPrice = 4;

    std::ostringstream builder;
    builder << "items=" << quantity;
    builder << ",total=" << quantity * unitPrice;

    std::string receipt = builder.str();

    std::cout << receipt << std::endl;
    std::cout << "length=" << receipt.size() << std::endl;
    return 0;
}
#include <iostream>
#include <sstream>
#include <string>

int main() {
    int quantity = ;
    int unitPrice = 4;

    std::ostringstream builder;
    builder << "items=" << quantity;
    builder << ",total=" << quantity * unitPrice;

    std::string receipt = builder.str();

    std::cout << receipt << std::endl;
    std::cout << "length=" << receipt.size() << std::endl;
    return 0;
}
output string stream An output string stream collects formatted pieces into one string value.