C++ fixed length string class?

前端 未结 10 1085
遇见更好的自我
遇见更好的自我 2020-12-17 17:56

Is there anything like this in Standard C++ / STL? Ideally it should be constructed like

fstring s = fstring(10);

I need to sometimes cons

10条回答
  •  無奈伤痛
    2020-12-17 18:23

    Why not use std::basic_string from STL as a fixed string class?

    You can use the constructor

    basic_string(
       size_type _Count,
       value_type _Ch,
       const allocator_type& _Al = Allocator ( )
    );
    

    as initializer.

    Later edit: Example:

    std::string my10CharStringInitializedWithSpace( 10, ' ');
    

提交回复
热议问题