Stringstream / streams / buffers .....

I have a stringstream. I want to use it to write unformatted data.
It works ok, I have a custom class with methods to put and get 'simple' data'
Now I'd want to get the data stored in its buffer. (the whole buffer). I'll use to send it over the network, or to save it into a binary file.
Sincerely, I dont know how to, and also I have the impression that some kind of copy are going to be made.

I dont know if can be a better solution to use memcpy, because I have allways access to the buffer used.
Any advice ?
Thanks.

Check this out:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <sstream>

using namespace std;

int main()
{
    stringstream my_stream;

    my_stream << "Hello, World!";

    const char * its_buffer = my_stream.str().c_str();

    cout << its_buffer << endl;

    cout << "\n(hit enter to quit...)";
    cin.get();

    return 0;
}
Topic archived. No new replies allowed.