文字处理问题?

softstarxy 2006-05-27 11:03:52
有一个TXT文件,里面的数字是
1
2
3



我需要把太改成1;2;3;。。。。。。请问应该如何做??
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weiting623 2006-05-28
  • 打赏
  • 举报
回复
刚才那个写错了一点点中文。重贴。
#include<fstream.h>
#include<conio.h>
void main()
{
char buf[5];
ifstream in("test.txt",ios::in);
try
{
if(in.fail())
throw "test.txt";
}
catch(char*)
{
cerr<<"读取文件失败!"<<endl;
return;
}
ofstream out("testnew.txt",ios::out);
try
{
if(out.fail())
throw "testnew.txt";
}
catch(char*)
{
cerr<<"创建新文件失败!"<<endl;
return;
}
do
{ in>>buf; //从文件读取一个串,直到换行
out<<buf;
out<<";";

}while(!in.eof());
in.close();
out.close();
return ;
}

weiting623 2006-05-28
  • 打赏
  • 举报
回复
#include<fstream.h>
#include<conio.h>
void main()
{
char buf[5];
ifstream in("test.txt",ios::in);
try
{
if(in.fail())
throw "test.txt";
}
catch(char*)
{
cerr<<"读取文件失败!"<<endl;
return;
}
ofstream out("testnew.txt",ios::out);
try
{
if(out.fail())
throw "testnew.txt";
}
catch(char*)
{
cerr<<"创建新文件!"<<endl;
return;
}
do
{ in>>buf; //从文件读取一个串,直到换行
out<<buf;
out<<";";

}while(!in.eof());
in.close();
out.close();
return ;
}

也写了一个,调过,没问题。
fallinleave 2006-05-27
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#define ENDL 10
int main()
{
FILE* fp;
FILE* fp1;
char buffer;
fp = fopen("test.txt","rw");
fp1 = fopen("tmp.txt","w");

while(!feof(fp))
{
buffer = fgetc(fp);
if(buffer == ENDL)
{
buffer = ';';
}
fputc(buffer,fp1);
}
fclose(fp);
fclose(fp1);
return 0;
}

33,319

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧