C++ array size dependent on function parameter causes compile errors

后端 未结 7 1811
甜味超标
甜味超标 2020-12-03 14:10

I have a simple function in which an array is declared with size depending on the parameter which is int.

    void f(int n){
        char a[n];
    };

    i         


        
7条回答
  •  天涯浪人
    2020-12-03 14:36

    Would it be reasonable to use a vector<> rather than an array? Or, since you're replacing a char *, a std::string? Those do work well with runtime sizing, although there may be other reasons not to use them.

提交回复
热议问题