使用ios::app的话,只能在末尾添加内容,且seekp方法会失效。在MSDN里搜索“openmode method”可以查到:
app, to seek to the end of a stream before each insertion.
也就说以app方式打开文件的时候,每次插入前,文件指针会自动移动到末尾,seekp方法无效。
要想达到题目要求,用ofstream是不行的,必须用fstream,同时以in和out的方式打开。即
使用ios::app的话,只能在末尾添加内容,且seekp方法会失效。在MSDN里搜索“openmode method”可以查到:
app, to seek to the end of a stream before each insertion.
也就说以app方式打开文件的时候,每次插入前,文件指针会自动移动到末尾,seekp方法无效。
要想达到题目要求,用ofstream是不行的,必须用fstream,同时以in和out的方式打开。即