I know how to do the other way round but don't know how to convert from name to account_name unless I convert it to string first. Please help. Thanks.
2 Answers
Name structure contains "account_name value" attribute. Look at "eosiolib\types.hpp"
account_name is just uint64_t; (eosiolib\types.h)
So you can:
account_name a = N("accname"); //eq of string_to_name(..)
name n = name {a};
a = n;
string accname = n.to_string();
Look at hello\hello.cpp for example.
Maybe this code can be useful:
account_name eosio_name = eosio::string_to_name(user); // convert to EOSIO name from variable
Where user
is: std::string user
.
This is basically a method to convert an std::string
to uint64_t
.