gpt4 book ai didi

c++ - std::fstream 文件句柄重用问题

转载 作者:搜寻专家 更新时间:2023-10-31 02:02:43 26 4
gpt4 key购买 nike

我不确定这段代码有什么问题:

fstream file_h("h_input.txt");
if(file_h.is_open()){
while(!file_h.eof()){
line.clear();
getline(file_h, line);
v_hrml.push_back(line);
}
file_h.close();
file_h.clear();
}
file_h("q_input.txt");
if(file_h.is_open()){
while(!file_h.eof()){
line.clear();
getline(file_h, line);
v_queries.push_back(line);
}
file_h.close();
file_h.clear();
}

对于重用file_h打开q_input.txt的代码段,编译器产生如下错误:

error: no match for call to ‘(std::fstream {aka std::basic_fstream<char>}) (const char [12])’
file_h("q_input.txt");

感谢您的想法。

TIA

最佳答案

您正在尝试调用一个变量。

改变

file_h("q_input.txt");

file_h.open("q_input.txt");

关于c++ - std::fstream 文件句柄重用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56821806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com