C++ equivalent of StringBuffer/StringBuilder?

前端 未结 10 920
说谎
说谎 2020-11-29 15:51

Is there a C++ Standard Template Library class that provides efficient string concatenation functionality, similar to C#\'s StringBuilder or Java\'s StringBuffer?

10条回答
  •  野性不改
    2020-11-29 16:30

    Since std::string in C++ is mutable you can use that. It has a += operator and an append function.

    If you need to append numerical data use the std::to_string functions.

    If you want even more flexibility in the form of being able to serialise any object to a string then use the std::stringstream class. But you'll need to implement your own streaming operator functions for it to work with your own custom classes.

提交回复
热议问题