Skip to content

Instantly share code, notes, and snippets.

@qpfiffer
Created April 3, 2017 22:42
Show Gist options
  • Save qpfiffer/d5fbd18daa9b6d75839e4b0430ea9562 to your computer and use it in GitHub Desktop.
Save qpfiffer/d5fbd18daa9b6d75839e4b0430ea9562 to your computer and use it in GitHub Desktop.
λ:~/src clang++ -o test_static_cast ./test_static_cast.cpp
./test_static_cast.cpp:7:42: error: no matching conversion for static_cast from 'std::string' (aka 'basic_string<char>') to 'std::vector<unsigned char>'
std::vector<unsigned char> new_str = static_cast<std::vector<unsigned char> >(test_string);
#include <cstdio>
#include <string>
#include <vector>
int main(int argc, char *argv[]) {
std::string test_string = "Hello, world!";
std::vector<unsigned char> new_str = static_cast<std::vector<unsigned char> >(test_string);
printf("%s\n", new_str);
}
@ikbrunel
Copy link

ikbrunel commented Apr 3, 2017

went with:

  string strAddrOrPubKey = params[0].get_str();
  std::vector<unsigned char> vchAddrOrPubKey(strAddrOrPubKey.length() +1 );
  std::copy(strAddrOrPubKey.c_str(), strAddrOrPubKey.c_str() + strAddrOrPubKey.length() + 1, vchAddrOrPubKey.begin());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment