文件读写,替换
我想做个程序,把里面的“,”换成“ ”(注,空格)
我不知道怎么用什么函数读写,高手请指教。小弟看到,读写文件,头都大了
真的不知道怎么下手,给我个样本,我把他背下来吧,谢谢
[解决办法]
文件相关函数
fopen
ftell
fread
fwrite
fclose
应该就差不多了
[解决办法]
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
int main( )
{
using namespace std;
ifstream is( "hello.txt ");
if(!is){
cout < < "Open file error " < < endl;
return 0;
}
string line;
ofstream out( "hi.txt ");
while(getline(is, line)){
replace(line.begin(), line.end(), ', ', ' ');
out < < line < < '\n ';
}
is.close();
out.close();
return 0;
}
[解决办法]
Thinkingking() ,你的代码有没有运行过啊?输出来的是乱码.