What is a portable method to find the maximum value of size_t?

后端 未结 5 1324
盖世英雄少女心
盖世英雄少女心 2020-12-05 09:35

I\'d like to know the maximum value of size_t on the system my program is running. My first instinct was to use negative 1, like so:

size_t max_size = (size_         


        
5条回答
  •  [愿得一人]
    2020-12-05 09:44

    As an alternative to bit-operations suggested in the other answers, you could do this in C++

    #include 
    size_t maxvalue = std::numeric_limits::max()
    

提交回复
热议问题