繁体   English   中英

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

[英]C++ : Dynamic C-String Usage in ifstreamObject.getline(c string, char limit)

我想知道是否有一种方法可以在使用 getline 方法时将空间动态分配给一个字符数组,该空间等于文件行中的空格数。 (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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM