Prepend std::string

后端 未结 4 544
醉梦人生
醉梦人生 2021-02-06 20:03

What is the most efficient way to prepend std::string? Is it worth writing out an entire function to do so, or would it take only 1 - 2 lines? I\'m not seeing anyth

4条回答
  •  春和景丽
    2021-02-06 20:39

    myString.insert(0, otherString);
    

    Let the Standard Template Library writers worry about efficiency; make use of all their hours of work rather than re-programming the wheel.

    This way does both of those.

    As long as the STL implementation you are using was thought through you'll have efficient code. If you're using a badly written STL, you have bigger problems anyway :)

提交回复
热议问题