今晚遇到点小问题,卡在基础知识,汗。。。
参考:https://segmentfault.com/q/1010000005936992
#include <iostream> #include <string.h> using namespace std; /* *解决需求:string[]转 char ** */ int main() { string array[] = { "1yuanpengfei", "2yuwangying", "3huangtilong", "4hongzhaoyang", "5gengchaogang", "6zhangshuai", "7shenshuai" }; int size = sizeof(array) / sizeof(string); char **instrumentID = new char *[size]; for (int i = 0; i < size; i++) { const char *charResult = array[i].c_str(); instrumentID[i] = new char[strlen(charResult) + 1]; strcpy(instrumentID[i], charResult); cout << instrumentID[i] << endl; } }
文章的脚注信息由WordPress的wp-posturl插件自动生成