std::vector resize vs reserve during fread

房东的猫 提交于 2019-12-02 08:42:58

If the vector is initially empty, then output[0] invokes undefined behaviour (regardless of how much space you have reserved), and on some platforms it may throw an exception.

Have found the problem, now I use code I called working

I wanted to avoid unnecessary resize because it works with data in memory, however after reserve output[0] do not exists.

What is more after read vector size would be zero and resize would destroy read data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!