Why is there a different string class in every C++ platform out there?

前端 未结 7 2015
北荒
北荒 2020-12-31 08:02

While I like programming in C++, I hate the idea of:
std::basic_string vs QString vs wxString vs .............
Doesn\'t the

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 08:44

    One of the tenants of C++ is "You don't pay for what you don't need." This means there does not need to be a one-size-fits-all string class that every C++ programmer MUST know and (more importantly) must USE. Maybe your project requires thread-safe strings. You can roll your own class. And you always have the option of using the existing std::string.

    It just so happens that in most cases std::string is good enough. But when it isn't, aren't you glad you aren't locked into it. Try to roll your own String class in Java and see how long it takes until you are pulling your hair out.

    As for your second point, if you are going to fight against a library you've added to your project, why did you add the library to your project in the first place? Part of the decision to use wxWidgets or QT is the acknowledgment that you must embrace its string class in your project (or at least a sizable portion of that project). Just like the decision to a "C" library means putting up with char* buffers and size parameters on all the functions.

    So, yes, learn the alternate string class. If you are using a library (and wish to become proficient with it) you can't decide to ignore part of the library just because "it's another string class". That makes no sense.

提交回复
热议问题