Advantages of using arrays instead of std::vector?

前端 未结 5 971
囚心锁ツ
囚心锁ツ 2020-12-05 20:41

I\'m currently seeing a lot of questions which are tagged C++ and are about handling arrays.
There even are questions which ask about methods/features for arrays which a

5条回答
  •  猫巷女王i
    2020-12-05 21:10

    Because C++03 has no vector literals. Using arrays can sometime produce more succinct code.

    Compared to array initialization:

    char arr[4] = {'A', 'B', 'C', 'D'};
    

    vector initialization can look somewhat verbose

    std::vector v;
    v.push_back('A');
    v.push_back('B');
    ...
    

提交回复
热议问题