How to cast the size_t to double or int C++
问题 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; int convertdata = data; the compiler will report warning. because it maybe overflow. Do you have some method like the boost or some other method to do the convert? 回答1: A cast, as Blaz Bratanic suggested: size_t data = 99999999; int convertdata = static_cast<int>(data); is likely to silence the warning (though in principle a compiler can warn about anything