How to initialize the dynamic array of chars with a string literal in C++?

后端 未结 3 1268
心在旅途
心在旅途 2021-01-21 17:24

I want to do the following:

std::unique_ptr buffer = new char[ /* ... */ ] { \"/tmp/file-XXXXXX\" };

Obviously, it doesn\'t work

3条回答
  •  长发绾君心
    2021-01-21 17:49

    I don't get why you're not using std::string; you can do str.empty() ? NULL : &str[0] to get a non-const pointer, so the constness of str.c_str() is not going to pose a problem.

    However, note that this is not null-terminated.

提交回复
热议问题