My question is that
I have a size_t data, but now I want to convert it to double or int.
If I do something like
size_t data = 99999999; in
If your code is prepared to deal with overflow errors, you can throw an exception if data is too large.
data
size_t data = 99999999; if ( data > INT_MAX ) { throw std::overflow_error("data is larger than INT_MAX); } int convertData = static_cast(data);