C++中有关文件操作的问题,请高手指点,多谢!
#include <string> #include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
void main(){
fstream inout("copyout",
fstream::binary ¦ fstream::ate ¦ fstream::in ¦ fstream::out);
if(!inout){
cerr < <"Unable to open the file" < <endl;
//return //EXIT_FAILURE;
}
fstream::pos_type end_mark=inout.tellg();
inout.seekg(0,fstream::beg);
string line;
while(inout.good()&&inout.tellg()!=end_mark&&getline(inout,line)){
fstream::pos_type mark=inout.tellg();
inout.seekp(0,fstream::end);
for(int index=0;index!=line.size();++index)
line[index]=toupper(line[index]);
inout < <line;
if(mark!=end_mark) inout < <" ";
inout.seekg(mark);
}
inout.clear();
inout.seekp(0,fstream::end);
//cin.get();
//cin.get();
}
在VC6.0中编译通过,并且可以执行,但是并没有在原有文件的末尾再追加一行,将原来文件中的小写字符转换为大写字符。 请高手指点,多谢!
[[it] 本帖最后由 hnbalp 于 2008-7-11 00:07 编辑 [/it]]