What is the size of sizeof(vector)? C++(sizeof(vector) 的大小是多少?C++)
问题描述
因此用户在 for 循环中输入值,向量将其推回,创建自己的索引.问题出现在第二个 for 循环中,我认为它必须对 sizeof(v)/sizeof(vector)
做一些事情.
So the user inputs values within the for loop and the vector pushes it back, creating its own index. The problem arises in the second for loop, I think it has to do something with sizeof(v)/sizeof(vector)
.
vector<int> v;
for (int i; cin >> i;)
{
v.push_back(i);
cout << v.size() << endl;
}
for (int i =0; i < sizeof(v)/sizeof(vector); i++)
{
cout << v[i] << endl;
}
输入值后如何确定向量的大小?(我对 C++ 很陌生,所以如果我犯了一个愚蠢的错误,我道歉)
How will I determine the size of the vector after entering values? (I'm quite new to C++ so If I have made a stupid mistake, I apologize)
推荐答案
使用 v.size()vector::size()
方法:i
.
sizeof
运算符返回编译时对象或表达式的大小(以字节为单位),对于 std::vector
来说是常量.
The sizeof
operator returns the size in bytes of the object or expression at compile time, which is constant for a std::vector
.
这篇关于sizeof(vector) 的大小是多少?C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sizeof(vector) 的大小是多少?C++


- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 从python回调到c++的选项 2022-11-16