C ++向量max_size(); [英] C++ vector max_size();

查看:70
本文介绍了C ++向量max_size();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在32位系统上.

  1. std :: vector< char> :: max_size()返回2 32 -1,大小为 char —1个字节
  2. std :: vector< int> :: max_size()返回2 30 -1,大小为 int —4个字节
  3. std :: vector< double> :: max_size()返回2 29 -1,大小为 double —8字节
  1. std::vector<char>::max_size() returns 232-1, size of char — 1 byte
  2. std::vector<int>::max_size() returns 230-1, size of int — 4 byte
  3. std::vector<double>::max_size() returns 229-1, size of double — 8 byte

谁能告诉我 max_size()取决于什么?

can anyone tell me max_size() depends on what?

,如果在64位系统上运行, max_size()的返回值是什么.

and what will be the return value of max_size() if it runs on 64 bit system.

推荐答案

只需

std::vector<dataType> v;
std::cout << v.max_size();

或者我们可以通过(2 ^ nativePointerBitWidth)/sizeof(dataType)-1 得到答案.例如,在64位系统上, long long (通常)是8字节宽,因此我们有(2 ^ 64)/8-1 == 2305843009213693951 .

Or we can get the answer by (2^nativePointerBitWidth)/sizeof(dataType) - 1. For example, on a 64 bit system, long long is (typically) 8 bytes wide, so we have (2^64)/8 - 1 == 2305843009213693951.

这篇关于C ++向量max_size();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆