pig*_*d10 3 c++ arrays char c-str
char el[3] = myvector[1].c_str();
Run Code Online (Sandbox Code Playgroud)
myvector[i] 是一个包含三个字母的字符串.为什么会出现此错误?
它返回char*类型,它是一个指向字符串的指针.您不能将此直接分配给这样的数组,因为该数组已经分配了内存.尝试:
const char* el = myvector[1].c_str();
Run Code Online (Sandbox Code Playgroud)
但是如果字符串本身被销毁或更改,因为指针将不再有效,所以要非常小心.