好吧,正如标题所说。我需要让我的程序读取一个完整的文件,但问题是如何让它读取完整的文件。我的代码非常大所以只需给出主代码。
while(Condition){
ide.pfopen >> ide.onum >> ide.comma >> ide.dffname;
getline(ide.pfopen,ide.extention);
ide.dffname.erase(std::remove(ide.dffname.begin(), ide.dffname.end(), ','), ide.dffname.end());
ide.tline = to_string(ide.onum) + ", " + string(ide.dffname) + ", " + string(ide.extention);
ide.fprocess << ide.tline<<endl;
}
那么我应该提出什么样的条件或任何其他解决方案呢?
编辑:代码应该用行输入整个文件。示例如下:
像这样,文件将被构造。程序应该读取行,直到没有行可读。18631,eeeeeeee,1a5ceba4,299,0
18631,1a5ceba4,1a5ceba4,299,0
18632,11206e0f,1b206e0f,299,0
18633,1fc47677,1fc47677,299,0
18634,2b8f8ee1,2b8f8ee1,299,0
18635,2b748eaf,2b748eaf,299,0
18636,2caf95b9,2caf95b9,299,0
18637,2dcb9d71,2dcb9d71,299,0
18638,2f4b9579,2f4b9579,299,0
18639,3a5d3114,3a5d3114,299,0
18640,3b54ad97,3b54ad97,299,0
答案 0 :(得分:0)
如果您为类或结构重载x.end()
,这会更简单:
operator>>
要阅读文件中的所有行:
struct NotPosted
{
int column1;
unsigned int column2;
unsigned int column3;
unsigned int column4;
int column5;
friend std::istream& operator>>(std::istream& input, NotPosted& np);
};
std::istream& operator>>(std::istream& input, NotPosted& np)
{
char comma;
input >> np.column1;
input >> comma;
input >> std::hex >> np.column2;
input >> comma;
input >> std::hex >> np.column3;
input >> comma;
input >> np.column4;
input >> comma;
input >> np.column5;
return input;
}