mercredi 2 décembre 2015

convert string to size_t

Is there a way to convert std::string to size_t? The problem is that size_t is platform dependable type (while it is the result of the sizeof). So, I can not guarantee that converting string to unsigned long or unsigned int will do it correctly.

EDIT: A simple case is:

std::cout<< "Enter the index:";
std::string input;
std::cin >> input;
size_t index=string_to_size_t(input);
//Work with index to do something

Aucun commentaire:

Enregistrer un commentaire