Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: const char * to stringstream

Tags:

c++

Is it possible to put a const char* into a string stream?

I think it's possible with the write() function in stringstream but I'm having trouble figuring out how to get the streamsize if i only know of the const char *.

Assuming size is my const char * variable:

stringstream s;
s.write(temp,size);

How do I get size? Thanks.

like image 447
user459811 Avatar asked Mar 03 '11 23:03

user459811


1 Answers

I tested it, and it works correctly...

#include <iostream>
#include <sstream>

using namespace std;

int main()
{
    stringstream s;
    const char* token = "HELLO";
    s << token;
    cout << s.str() << endl;
    return 0;
}

[facu@arch ~]$ g++ p.cpp 
[facu@arch ~]$ ./a.out 
HELLO
like image 52
fpointbin Avatar answered Sep 29 '22 08:09

fpointbin