How can I discover the size/length(in bytes) of a std::vector?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a vector and I want to write and read it to a file but it is not possible to determine the logical size of a vector using the sizeof operator. So what shall I do? 回答1: A c++ std::vector has a method size() which returns its size. EDIT: as I get it now you need to compute the memory a given vector uses. You can't use sizeof for that as a vector uses dynamic memory and stores only a pointer of a dynamic array containing its elements. So my best suggestion would be to multiply the memory each element requires by the number of elements.