ostream& seekp( streampos pos );
ostream& seekp( streamoff off, ios::seek_dir dir );
Parameters
pos
The new position value; streampos is a typedef equivalent to long.
off
The new offset value; streamoff is a typedef equivalent to long.
dir
The seek direction specified by the enumerated type ios::seek_dir, with values including:
ios::beg Seek from the beginning of the stream.
ios::cur Seek from the current position in the stream.
ios::end Seek from the end of the stream.
多看看msdn,有很大好处的。
cout << "input the good ID you want to alter its information!"<<endl;
cin >> ID;
//数据读入内存
ioFile >> agood.goodID >> agood.goodName >> agood.goodNumber ;
while(ioFile.good())
{
streampos here = ioFile.tellp();//?
if (strcmp(agood.goodID,ID) == 0)
{
ioFile.seekp(40,ios::cur);//?
//执行修改操作
agood.goodNumber = 80;
//写回文件操作,替换原来记录
ioFile.wirte();//这个怎么用?
break;
}
ioFile >> agood.goodID >> agood.goodName >> agood.goodNumber;
}
if (ioFile.eof())
cout << "this good is not exist!" <<endl;