How to read a file into vector in C++?

前端 未结 6 1919
执念已碎
执念已碎 2020-12-01 06:34

I need to read from a .data or .txt file containing a new float number on each line into a vector.

I have searched far and wi

6条回答
  •  情歌与酒
    2020-12-01 07:11

    1. In the loop you are assigning value rather than comparing value so

    i=((Main.size())-1) -> i=(-1) since Main.size()

    Main[i] will yield "Vector Subscript out of Range" coz i = -1.

    2. You get Main.size() as 0 maybe becuase its not it can't find the file. Give the file path and check the output. Also it would be good to initialize the variables.

提交回复
热议问题