We have created and filled some std::vector<uchar> with openCV imencode for example. Now we want to stream it for example into some http_lib which can take some sort of ostream (ostringstream) for example, or we just want to save in while we debug our programm with ofstream. So I wonder how to put std::vector<uchar> into std::ostream?
We have created and filled some std::vector<uchar> with openCV imencode for example. Now we
Share
Use
write:The ostream expects naked
chars, but it’s fine to treat uchars as those by casting that pointer. On older compilers you may have to say&v[0]instead ofv.data().You can return the result of
write()as anotherstd::ostream&or as aboolif you like some error checking facilities.