C++ : ifstreamObject.getline(c string, char limit) 中的动态 C 字符



我想知道在使用 getline 方法时,是否有办法将空间动态分配给字符 aray,等于文件中行中的空格量。(C++)

int main(){    
    char *theLine;
    ifstream theFile;
    //set theLine = new char[sizeOftheFileLine]
    //is there a way do the above
    theFile.getline(theLine, 500);
    return 0;
}

如果使用 std::getline ,则会获得所需的行为。

std::string theLine;
std::ifstream theFile;
// ....
std::getline(theFile, theLine);

最新更新