c++ - Converting a C-string to a std::vector<byte> in an efficient way -


I want to convert the c-style string to byte-vector. A working solution will change each character manually and it will be pushed to vector. However, I am not satisfied with this solution and I have to find another great way.

One of my efforts was the following:

  std :: vector & lt; Byte & gt; MyVector; & Amp; MyVector [0] = (byte) "MyStream";  

The bugs and me one

error C2106: '=': the left operation must be l-value

What is the right way to do this?

The most basic thing would be:

  const char * cstr = "Bla" std :: vector & lt; Char & gt; Vec (cstr, cstr + strlen (cstr));  

Of course, if you know it, do not calculate the length.

The more common solution is to use the square:

  const four * cestrate; Std :: string str = cstr;  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -