| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 797 人关注过本帖
标题:文本去除标点符号问题
只看楼主 加入收藏
z8869113
Rank: 2
等 级:论坛游民
帖 子:44
专家分:14
注 册:2010-12-14
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:3 
文本去除标点符号问题
各位大大们好~

我在将文本里的标点符号去掉的问题中遇到了问题

运算结果中为什么全部是乱码呢?

求大神解答
代码:
#include <iostream.h>
#include <fstream.h>
#include<ctype.h>



void del_space(char *str)   //去除符号函数
{
        int i, j;

        for (i = j = 0; str[i] != '\0'; i++)
        {
                if (!ispunct(str[i]))
                {
                       str[j++] = str[i];
                }
        }
        str[j] = '\0';
}



void main()
{
    ifstream myf("1.txt");  //打开文件1

    ofstream myf1("2.txt");   //打开文件2



    if (myf.fail())   //文件1打开失败
    {
        cout<<"file no exist!"<<endl;
        return;
    }



    char txt[56];

    myf>>txt;



    while (!myf.eof() )
    {

            del_space(txt);   //删除

            cout<<txt<<endl;   

            myf1<<txt;       //写到文件2
            
            myf>>txt;        //读入

    }

}
搜索更多相关主题的帖子: include 标点符号 
2011-12-23 09:35
z8869113
Rank: 2
等 级:论坛游民
帖 子:44
专家分:14
注 册:2010-12-14
收藏
得分:0 
没人么~
2011-12-23 10:56
z8869113
Rank: 2
等 级:论坛游民
帖 子:44
专家分:14
注 册:2010-12-14
收藏
得分:0 
我自己又去网上找了个实现方法

带进去后发现只能输出前面十几个词而已
#include <iostream>
#include <fstream>
#include<ctype.h>
#include <string>
using namespace std;



void main()
{
    ifstream myf("1.txt");  //打开文件1

    ofstream myf1("2.txt");   //打开文件2



    if (myf.fail())   //文件1打开失败
    {
        cout<<"file no exist!"<<endl;
        return;
    }


    char txt[256];

    string tx;

    myf>>txt;
    tx=txt;



    while (!myf.eof() )
    {

    size_t n=0;                                 //从这里开始是去除符号函数
    size_t count=0;
    unsigned char c1,c2;
    setlocale(LC_ALL,"");
    while(n <tx.size()-1)
    {         
        count=mblen(&tx[n],2);
          if (count==1)               
            tx.erase(n,1);
        else         
        {         
            c1=(unsigned char)tx[n];
        c2=(unsigned char)tx[n+1];
        if (((c1>=0xa1&&c1 <=0xa9)&&(c2>=0xa1&&c2 <=0xfe))||((c1>=0xa8&&c1 <=0xa9)&&(c2>=0x40&&c2 <=0xa0)))  
            tx.erase(n,2);
        else              
            n++;         
        }      
    }            


               

            myf1<<tx;

            cout<<tx<<endl;

            myf>>txt;

            tx=txt;

    }

}
2011-12-23 10:59
wj7072005
Rank: 2
等 级:论坛游民
帖 子:7
专家分:47
注 册:2011-12-16
收藏
得分:20 
for (i = j = 0; str[i] != '\0'; i++)
        {
                if (!ispunct(str[i]))
                {
                       str[j++] = str[i];
                }
        }
        str[j] = '\0';

写的乱糟糟的
2011-12-23 12:47
快速回复:文本去除标点符号问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018650 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved