Creating arrays in C++ without knowing the length ahead of time

前端 未结 3 765
遥遥无期
遥遥无期 2021-01-19 18:14

I\'m working on a small program to help speed up some data analysis for my lab work. It\'s supposed to read in data from a text file, create a bunch of arrays containing thi

3条回答
  •  臣服心动
    2021-01-19 18:38

    You say that you're not comfortable with dynamically-sized arrays, or std::vector.

    I'm afraid that you'll have to figure out how to get comfortable here, because that's precisely what's std::vector is for.

    The only other alternative is to use the gcc compiler. gcc does allow you to have variable-sized arrays. It's a compiler extension, it's not standard C or C++:

    void method(size_t n)
    {
       dataPoint array[n];
    
       // Do something with the array.
    }
    

提交回复
热议问题