去掉TXT文档中的空格 换行和标点符号

dian729506189 2012-04-19 05:18:21
编程实现去除txt文档中所有的空格 和换行。就类似于这样:

庆历四年春,滕子京 谪守巴陵 郡。越明
年,政通人和,
百废具兴。乃重 修岳阳楼 ,增其旧制, 刻唐贤今人
诗赋于其上。属予作文
以记之。

去除以后应该变为:庆历四年春,滕子京谪守巴陵郡。越明年,政通人和,百废具兴。乃重修岳阳楼,增其旧制,刻唐贤今人诗赋于其上。属予作文以记之。

求大神指导,本人一菜鸟。最好C++实现!!
...全文
1144 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
evencoming 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]
编译能通过,但是结果是乱码!
a.txt里面编程乱码,out.txt没见出来!!

引用 8 楼 evencoming 的回复:
引用 7 楼 的回复:
引用 6 楼 的回复:
编译不过、、、

引用 3 楼 的回复:
C/C++ code


#include<itreator>
#include<algorithm>
#include<fstraem>
#incl……
[/Quote]
你不是说要原来的文件吗?不要out.txt吗?
所以remove 这个调用给删除了。。
乱码问题我看看。。还是得找编译器。。
dian729506189 2012-04-19
  • 打赏
  • 举报
回复
编译能通过,但是结果是乱码!
a.txt里面编程乱码,out.txt没见出来!!
[Quote=引用 8 楼 evencoming 的回复:]
引用 7 楼 的回复:
引用 6 楼 的回复:
编译不过、、、

引用 3 楼 的回复:
C/C++ code


#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filen……
[/Quote]
evencoming 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
错误太多 ,越调越出错。。!

引用 4 楼 evencoming 的回复:
引用 3 楼 的回复:
C/C++ code

#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *fi……
[/Quote]
看8L,,手头没编译器的后果。。
靠眼界查错。。
dian729506189 2012-04-19
  • 打赏
  • 举报
回复
嗯,这个能用!谢啦!!
[Quote=引用 9 楼 hen_hao_ji 的回复:]
C/C++ code

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
ifstream in("1.txt", ios::in);
ofstream out("2.txt", ios::out);

string str……
[/Quote]
dian729506189 2012-04-19
  • 打赏
  • 举报
回复
错误太多 ,越调越出错。。!
[Quote=引用 4 楼 evencoming 的回复:]
引用 3 楼 的回复:
C/C++ code

#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *outname="out.……
[/Quote]
hen_hao_ji 2012-04-19
  • 打赏
  • 举报
回复

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
ifstream in("1.txt", ios::in);
ofstream out("2.txt", ios::out);

string str;
while(in&&in>>str)
{
out<<str;

}

return 0;
}
evencoming 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
引用 6 楼 的回复:
编译不过、、、

引用 3 楼 的回复:
C/C++ code


#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
……
[/Quote]
[code=C/C++]
#include<cstdio>
#include<itreator>
#include<algorithm>
#include<fstream>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *outname="out.txt";
remove_copy_if(
istreambuf_iterator<char>(ifstream(filename,ios_base::binary)),
istreambuf_iterator<char>(),
ostreambuf_iterator<char>(ofstream(outname,ios_base::binary)),
isspace);
remove(filename);
rename(outname,filename);
return 0;
}

[/CODE]
evencoming 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
编译不过、、、

引用 3 楼 的回复:
C/C++ code


#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *……
[/Quote]
#include<fstraem>
头文件写错了。
还少了个 cstdio
改成下面这样、吧:
[code=C/C++]
#include<cstdio>
#include<itreator>
#include<algorithm>
#include<fstream>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *outname="out.txt";
remove_copy_if((istreambuf_iterator<char>(ifstream(filename,ios_base::binary)),
istreambuf_iterator<char>(),
ostreambuf_iterator<char>(ofstream(outname,ios_base::binary)),
isspace);
remove(filename);
rename(outname,filename);
return 0;
}
[/CODE]
applegeeE 2012-04-19
  • 打赏
  • 举报
回复
编译不过、、、[Quote=引用 3 楼 的回复:]
C/C++ code


#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *outname="out.txt";
remo……
[/Quote]
querdaizhi 2012-04-19
  • 打赏
  • 举报
回复

#include<stdlib.h>
#include<stdio.h>
#include<string.h>


int main()
{
FILE *fp = fopen("test.txt" , "r");
char buffer[1024];
memset(buffer , '\0' , sizeof(buffer));
int size = fread(buffer,sizeof(char) ,1024 , fp);

for(int i=0;i<size;i++)
{
if(buffer[i] == ' ' || buffer[i] == '\n')
continue;
else
printf("%c" , buffer[i]);
}
return(0);
}
evencoming 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
C/C++ code

#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *outname="out.txt";
remove……
[/Quote]
少了个头文件
#include<cstdio>
evencoming 2012-04-19
  • 打赏
  • 举报
回复
[code=C/C++]
#include<itreator>
#include<algorithm>
#include<fstraem>
#include<cctype>
using namespace std;

int main()
{
const char *filename="a.txt";
const char *outname="out.txt";
remove_copy_if((istreambuf_iterator<char>(ifstream(filename,ios_base::binary)),
istreambuf_iterator<char>(),
ostreambuf_iterator<char>(ofstream(outname,ios_base::binary)),
isspace);
remove(filename);
rename(outname,filename);
return 0;
}
[/CODE]
dian729506189 2012-04-19
  • 打赏
  • 举报
回复
这个随便,重新生成一个文件也行,但是我觉得最好是在源文件的基础上直接去除就行,这样方便我后期的处理!![Quote=引用 1 楼 的回复:]

要保存到一个文件吗?
[/Quote]
hen_hao_ji 2012-04-19
  • 打赏
  • 举报
回复
要保存到一个文件吗?
文本整理器是一款针对文文章格式而设计的文本编辑软件。对一篇格式不规范的文章,只需点击几个按钮,就可把它整理成规范格式。它提供了大量实用的整理工具,可满足各种不同的整理要求,使你从繁琐的修改工作摆脱出来。它提供的批量整理功能,可以使你在几分钟内整理上百篇文本,再不用为手上的大量不规范的文本发愁了。   主要功能简介   ⑴编辑功能:      编辑功能类似于记事本,可直接编辑各种纯文本文件,如:.txt、.htm、.ini等。   ⑵对空格的整理:      去除所有空格:包括半角空格、全角空格、Tab符;      去除段落首尾空格:用于文字有英文句子的情况,不至于把有用的空格去掉;   ⑶对段落的整理:      段首缩进:利用在段前加入空格的方式实现缩进,缩进的空格可以是全角空格、半角空格或Tab符;       去除段落间空行:使段落紧密排列;      合并空行:可把多个空行合并为一个, 用于去除多余的空行;      只空一行:在没有空行的段落后加入一个空行,有多个空行的段落只保留一个空行,以保证各段落间都只空一行。      合并段落:把几个段落合并为一个,并去除段落间的空格。      合并行:把以硬回车换行的行合并为一段。      段间加空行:在段落后添加一个空行,不论它原来是否有空行。   ⑷对标点符号的整理:      对常用标点符号进行半角-全角转换,包括逗号、分号、冒号、引号等多种标点。   ⑸文字的繁体、简体转换,GB码与BIG5码的转换。   ⑹其它:包括修正局部乱码、数字字母的大小写和全半角转换、Htm与Txt的转换、字数统计、查看二进制文本、整理C源代码、修改文件扩展名等。   特色功能:   ⑴多窗口编辑:      可同时打开四个文档,并排排列在窗口,便于进行对照编辑。   ⑵自动整理:      可以把几项整理功能设定为整理方案,按方案设定内容一次整理到位,适合于整理多个格式相似整理结果也要求相似的文档。简化了整理过程。   ⑶批量整理:      用设定的整理方案对磁盘上的多篇文档成批整理。省事又快捷。特别适合于整理网络小说之类的文档。   ⑷文件合并:      把磁盘上选择的文件合并为一个文件。   ⑸插入功能:      提供了四个插入文本框,相当于四个可视化剪贴板,而且多样化的插入方式使它比剪贴板更好用。   ⑹查找功能:      除了普通的查找/替换功能外,利用替换表可以实现多组关键字的查找/替换,利用界限查找可以实现指定边界的查找/替换。   ⑺特殊符号的快速输入:      提供了标点符号、数字序号、特殊符号、希腊字母等九张符号表,可以实现特殊符号的快速输入。   使用说明:如果需要使用“替换表”功能,运行“绿化.bat”注册相关控件即可。

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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