[英]c++ how to create an empty char array of the size of an existing char array?
我想创建一个大小为pLine的aValue,因为如果长度超过128,我不希望aValue切断该行。
char aValue[128];
sscanf(pLine, "Word %127s", aValue);
希望你能提前帮助我。
使用std::string
,如:
std::string aValue;
aValue.resize(strlen(pLine));
然后你可以得到c-string:
aValue.c_str();
据我所知,你需要一个长度为pLine最大值的缓冲区
char *aValue=new char[strlen(pLine)];
sscanf(pLine, "Word %s", aValue);
不要忘记在使用后删除aValue:
delete[] aValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.