【发布时间】:2014-12-31 17:18:09
【问题描述】:
基本上,我正在尝试这样做:
char x[] = "hello";
char* y = new char[sizeof(x)](x); // won't work.
有没有办法干净地做到这一点?请勿使用原始数组或原始指针,请不要使用 cmets。
【问题讨论】:
-
不使用原始数组或原始指针是什么意思?你问的不是这个吗?
-
如果您按照标签的建议使用 C++11,那么您可以使用 std::array in the manner shown here。
-
std::string是干净利落的方式。 -
@Daniel 他要求我们不要像
DO NOT USE raw arrays, or raw pointers那样做cmets