sizeof( vector<> )

#include <iostream.h> #include <vector> using namespace std; struct Node { int id; vector<int> score; }; void DisplayVector(vector<int> &v) { cout<<"sizeof(v) = "<<sizeof(v)<<endl; for(vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout<<*it<<'\t'; } cout<<endl; } void DisplaySize() { cout<<"sizeof(vector<char>) = "<<sizeof(vector<char>)<<endl; cout<<"sizeof(vector<int>) = "<<sizeof(vector<int>)<<endl; cout<<"sizeof(vector<short>) = "<<sizeof(vector<short>)<<endl; cout<<"sizeof(vector<double>) = "<<sizeof(vector<double>)<<endl; cout<<"sizeof(vector<long>) = "<<sizeof(vector<long>)<<endl; cout<<"sizeof(vector<float>) = "<<sizeof(vector<float>)<<endl; } int main() { DisplaySize(); Node node; cout<<"sizeof(Node) = "<<sizeof(node)<<endl; node.id = 1; node.score.push_back(10); node.score.push_back(20); node.score.push_back(25); cout<<"sizeof(Node) = "<<sizeof(node)<<endl; DisplayVector(node.score); return 0; }


输出结果:

sizeof(vector<char>) = 16
sizeof(vector<int>) = 16
sizeof(vector<short>) = 16
sizeof(vector<double>) = 16
sizeof(vector<long>) = 16
sizeof(vector<float>) = 16
sizeof(Node) = 20
sizeof(Node) = 20
sizeof(v) = 16
10 20 25

<wbr></wbr>

<wbr></wbr>

不管插入多少数据,sizeof(vector<>)大小不变,在vc下始终为16,在vs下据说20

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值