2
        [[eosio::action]]
        void hi(){
            string strNum;
            strNum.push_back('3');
            float currNum = std::stof(strNum);//  
            print("currNum=",currNum);
        }

then

MacBook-Plou:testkeys treaser$ cleos push action fy hi '[]' -p testhero@active
Error 3070002: Runtime Error Processing WASM
Error Details:
wabt execution failure (out of bounds memory access)
pending console output: 
4
  • Please add a decent description about what you are trying to do.
    – tmm
    Commented Nov 16, 2018 at 16:27
  • he's obviously trying to parse a string containing a number into a float
    – ekkis
    Commented Feb 3, 2019 at 1:28
  • @Lou, I have this same issue. did you solve it?
    – ekkis
    Commented Feb 3, 2019 at 1:28
  • this seems important enough for me to report it as a bug on github: github.com/EOSIO/eosio.cdt/issues/404
    – ekkis
    Commented Feb 3, 2019 at 1:33

1 Answer 1

1

I couldn't make that happen either but I did make this work:

std::string s("limit: 686.97");
float limit = atoi(s.c_str());
printf("limit [%f]\n", limit);

* Edit I *

of course, that gets us to integer. sadly the atof is not available, so I think counting the number of digits in the string, removing the dot, converting to an integer and then dividing by the number of digits would give the correct value. bloody mess

float _stof(std::string s)
{   
    std::size_t i = s.find(".");
    int digits = s.length() - i - 1;
    s.erase(i, 1);
    return atoi(s.c_str()) / pow(10, digits);
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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