samedi 26 mars 2022

How to convert string having characters or ip address to integer and back from integer to the original string

I need to convert a string having characters and digits( eg,an ipaddress or xyz123) to integer to store in DB and while retrieving needs to convert the integer to the same string as xyz123. How can I do this in C++14.

I have used the stoi function to convert from string to int and it's creasing with the error terminate called after throwing an instance of 'std::invalid_argument' what(): stoi

Also using atoi(str.c_str()) outputs only the digits in the string.

While converting this integer to string, I am getting back only the digits and cannot construct the original string which I have converted.

Aucun commentaire:

Enregistrer un commentaire