6

I declared a variable value = "0.0001 EOS"; , inside my action I want to transfer those asset to a account .I am having difficulty to typacasting this string into the eosio::asset value . my code goes like this :

...
std::string value = "0.0001 EOS";
eosio::asset tosend = (eosio::asset)value;
...

it gives me error

 error: no matching conversion for C-style cast from 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') to
     'eosio::asset'
           eosio::asset tosend = (eosio::asset)value;

if I pass the tosend value from cleos command it would work fine . so my question is can I typcast the string value into eosio::token ?

4

I find the way to solve this problem .I use the function of symbol.hpp which is located at eosiolib/symbol.hpp inside our eos . First of all I create a string and then assign some amount to the struct . My code goes like this

...
std::string sym = "EOS";
symbol_type symbolvalue = string_to_symbol(4,sym.c_str());
eosio::asset tosend;
tosend.amount = 10001;
tosend.symbol = symbolvalue;
print("tosend value is ______",tosend);
... 

so the amount here is 1.0001 EOS. it works for me . If anybody have better approach please feel free to share .

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.