【 在 clwd 的大作中提到: 】
: 如何以逗号为分隔符把这个一千万个字符串快速存进一个vector里面
原地构建吧
#define CHARLENGTH(array) ((sizeof(array)) / (sizeof(array[0])))
std::vector<const char*> v(10000000);
char longWord[] = "ab,cd,ef,g,h,ijk,opq,r,s,tuvw,xy,z";
char* wordCursor = longWord;
uint32_t vectorCursor = 0;
for (uint32_t idx = 0; idx < CHARLENGTH(longWord); idx++) {
if (longWord[idx] == ',') {
longWord[idx] = '\0';
*(v.data() + vectorCursor) = wordCursor;
vectorCursor++;
wordCursor = longWord + idx + 1;
}
}
*(v.data() + vectorCursor) = wordCursor;
v.erase(v.begin() + vectorCursor + 1, v.end());
v.shrink_to_fit();
--
FROM 211.249.40.*