Convert char* to string C++

后端 未结 5 1968
轮回少年
轮回少年 2021-01-31 03:29

I know the starting address of the string(e.g., char* buf) and the max length int l; of the string(i.e., total number of characters is less than or equ

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 03:59

    Use the string's constructor

    basic_string(const charT* s,size_type n, const Allocator& a = Allocator());
    

    EDIT:

    OK, then if the C string length is not given explicitly, use the ctor:

    basic_string(const charT* s, const Allocator& a = Allocator());
    

提交回复
热议问题