这是主函数中定义的部分
ifstream infile("hardware.dat",ifstream::in | ifstream::binary);
ofstream outfile("hardware.dat",ofstream::out | ofstream::app);
然后我想在一个类的成员函数里对hardware.dat进行操作
void newFile::printRecord(void)
{
cout << "***打印开始" << endl;
cout << setw(6) << "记录号"
<< setw(6) << "数量"
<< setw(6) << "价格"
<< setw(20) << "名称" << endl;
infile.seekg(ifstream::beg);
while(infile)
{
string temp;
getline(infile,temp);
cout << temp << endl;
}
cout << "***打印完毕" << endl;
}
但是编译时发现while语句体完全没有被执行
也就是说infile流无效 但是调试没看出来问题
求指教……
ifstream infile("hardware.dat",ifstream::in | ifstream::binary);
ofstream outfile("hardware.dat",ofstream::out | ofstream::app);
然后我想在一个类的成员函数里对hardware.dat进行操作
void newFile::printRecord(void)
{
cout << "***打印开始" << endl;
cout << setw(6) << "记录号"
<< setw(6) << "数量"
<< setw(6) << "价格"
<< setw(20) << "名称" << endl;
infile.seekg(ifstream::beg);
while(infile)
{
string temp;
getline(infile,temp);
cout << temp << endl;
}
cout << "***打印完毕" << endl;
}
但是编译时发现while语句体完全没有被执行
也就是说infile流无效 但是调试没看出来问题
求指教……