Vector vs string

前端 未结 7 666
挽巷
挽巷 2020-12-06 09:46

What is the fundamental difference, if any, between a C++ std::vector and std::basic_string?

相关标签:
7条回答
  • 2020-12-06 10:36

    One difference between std::string and std::vector is that programs may construct a string from a null-terminated string, whereas with vectors they cannot.

    std::string a = "hello";          // okay
    std::vector<char> b = "goodbye";  // compiler error
    

    This often makes strings easier to work with.

    0 讨论(0)
提交回复
热议问题