How to convert vector of char to stringstream

Rahul_cs12

is it possible to convert char vector to std::stringstream? For example:

std::vector<unsigned char> data;
std::stringstream st(????);

Is there any way by which I can assign value of data to st?

Barry

If we look at the std::stringstream constructors, we see that the second one is:

explicit basic_stringstream( const std::basic_string<CharT,Traits,Allocator>& str,
                ios_base::openmode mode = ios_base::in|ios_base::out );

And the constructors of basic_string include:

template< class InputIt >
basic_string( InputIt first, InputIt last, 
              const Allocator& alloc = Allocator() );

Thus, we can do:

std::vector<unsigned char> data(20);

std::stringstream st(std::string(data.begin(), data.end()));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related