由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - question on reserve()
相关主题
question on reserve() in vector container.C++: What is the difference between the two approaches?
关于正交向量(orthogonal vectors)的算法菜鸟请教smart pointer
STL/vector引用成员变量。c++ copy reference 还是deep copy
Is it possible to initialize container in initialization list?C++真的很邪恶
用数组做参数,在函数内部如何知道数组的size?C++要是有null object就好了
C++ vector 到底能多大C++请教,使用c++ vector iterator后输出vector数据出错
how do I reseat a reference?OO design for reservation system?
请教一下这个template function在gcc下要怎么修改Restaurant Reservation System...
相关话题的讨论汇总
话题: reserve话题: question话题: vector话题: 10话题: int
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
vector x;
x.reserve(3);
x[0]=10; x[1]=20; x[2]=30;
x.reserve(10);
for(int i=0;i<3;i++) { cout << x[i] << endl; }
向量开始是3,长度不够,我们增加到10.但是增加后原来赋的值被冲了。有没有办法保
留原来的值? 必须用另一个vector吗?
t****t
发帖数: 6806
2
you reserved space, but the size is still 0. it's invalid to assign directly
to [0], [1], [2].

【在 c**********e 的大作中提到】
: vector x;
: x.reserve(3);
: x[0]=10; x[1]=20; x[2]=30;
: x.reserve(10);
: for(int i=0;i<3;i++) { cout << x[i] << endl; }
: 向量开始是3,长度不够,我们增加到10.但是增加后原来赋的值被冲了。有没有办法保
: 留原来的值? 必须用另一个vector吗?

c**********e
发帖数: 2007
3
Thank you. This is very interesting. I use push_back, then reserving more
space does not wash out old data.

directly

【在 t****t 的大作中提到】
: you reserved space, but the size is still 0. it's invalid to assign directly
: to [0], [1], [2].

1 (共1页)
进入Programming版参与讨论
相关主题
Restaurant Reservation System...用数组做参数,在函数内部如何知道数组的size?
std::string::reserve()C++ vector 到底能多大
有人说这个办法可以解决栈溢出how do I reseat a reference?
问个memory leak的问题请教一下这个template function在gcc下要怎么修改
question on reserve() in vector container.C++: What is the difference between the two approaches?
关于正交向量(orthogonal vectors)的算法菜鸟请教smart pointer
STL/vector引用成员变量。c++ copy reference 还是deep copy
Is it possible to initialize container in initialization list?C++真的很邪恶
相关话题的讨论汇总
话题: reserve话题: question话题: vector话题: 10话题: int