Short example of using string stream in C++ to build a string.

#include <stdio.h>
#include <iostream>
#include <sstream>


int main(int argc, char **argv) {
    std::stringstream ss;

    ss << "Hello, World" << "\n" << 42 << "\n";


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

 std::cout << str;

    return 0;
}




Last Modified: 23 February 2017

Releated Posts


2017-04-25 - Linux Programming - Signals the easy way
2017-03-01 - Shooting yourself in the head with threads
2013-08-22 - CPP - Prevent an object by being copied with boost::noncopyable
2013-03-29 - CPP - Why you need a copy constructor
2013-03-27 - CPP -boost::optional
2012-11-06 - C++ - Stringstream example
2012-08-09 - C++ - Check an IP Address is in a IP Mask
2012-06-30 - CPP - Creating A basic python wrapper
2012-06-16 - CPP - Using gperf
2012-05-10 - CPP - Optional function arguments
2012-03-19 - CPP - Read / Write std::map to a file.