一、把QQ群的聊天记录txt格式导出

消息管理器 -> 选择要导出的群 -> 右击、导出
 
这里要注意 : 导出之后的 文本是 unicode 编码的,需要转换 ==|| 之前不知道,搞了大半天。
重新建一个txt , 把原来的 txt 内容 复制 到 新的 txt ,保存就行了。
 

二、详细代码

1. head.h

 #ifndef TxtSearch
#define TxtSearch #include<string>
#include<map>
#include<set>
#include<iostream>
#include<vector>
#include<fstream>
#include<sstream>
#include<ctype.h> typedef unsigned char BYTE;
typedef unsigned short WORD; bool IsChineseChar(WORD DoubleByte); void WordAndChar_print(std::string ); class TextQuery
{
public: typedef std::vector<std::string>::size_type line_no; void read_file(std::ifstream & );
std::set<line_no> run_query(const std::string&) const;
std::string text_line(line_no) const;
private:
void store_file( std::ifstream & );
void build_map(); std::vector<std::string> lines_of_text;
std::vector<std::string> bak_lines_of_text;
std::map< std::string,std::set<line_no> > word_map; }; void print_resluts(const std::set< TextQuery::line_no> & ,
const std::string & , const TextQuery &); #endif

2、function.cpp

 #include"head.h"

 bool IsChineseChar(WORD DoubleByte)
{
return ( (DoubleByte < ) || (DoubleByte > ) );
} void TextQuery::read_file( std::ifstream & is)
{
store_file(is);
build_map();
} std::set<TextQuery::line_no> TextQuery::run_query(const std::string& str) const
{
std::map<std::string, std::set<line_no> >::const_iterator
loc = word_map.find(str); if(loc == word_map.end())
{
return std::set<line_no>();
} return loc->second;
}
std::string TextQuery::text_line(line_no line_num) const
{
if(line_num < lines_of_text.size())
return lines_of_text[line_num]; throw std::out_of_range("line num is out of range");
} void TextQuery::store_file(std::ifstream & is)
{
std::string txtline;
while(std::getline(is,txtline))
{
lines_of_text.push_back(txtline);
int len = txtline.length();
for(int i = ; i <len ; i ++) //pretreatment
{
bool b1 = ,b2 =;
if(!IsChineseChar(txtline[i])
&&!isalnum(txtline[i]) )
txtline[i] = ' ';
b1 = IsChineseChar(txtline[i]);
if(i + < len)
b2 = IsChineseChar(txtline[i+]);
} bak_lines_of_text.push_back(txtline);
}
} void TextQuery::build_map()
{
for(line_no line_num = ; line_num != bak_lines_of_text.size() ; ++line_num)
{
std::istringstream strline(bak_lines_of_text[line_num]);
std::string word;
while(strline >> word)
{
word_map[word].insert(line_num);
}
}
} void print_resluts(const std::set< TextQuery::line_no> & ss,
const std::string & str, const TextQuery &tq)
{
typedef std::set< TextQuery::line_no> lineset; lineset::size_type size = ss.size();
std::string path = str + ".txt";
std::ofstream outfine(path);
outfine<<str<<" occurs "<<size <<"times"<<std::endl;
lineset::const_iterator it = ss.begin(); for(; it != ss.end() ; ++ it)
{
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it)<<std::endl;
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it+)<<std::endl;
}
}

3、main.cpp

 #include"head.h"

 int main()
{
std::ifstream infile("char.txt"); if(!infile.is_open())
{
printf("No input file!\n");
return -;
}
TextQuery tq;
tq.read_file(infile);
std::string query;
while (printf("enter user ID to look for:\n"),
std::cin>>query )
{
std::set<TextQuery::line_no> loc = tq.run_query(query);
print_resluts(loc,query,tq);
}
return ;
}

三、需要改进的地方

1、

 for(; it != ss.end() ; ++ it)
{
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it)<<std::endl;
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it+)<<std::endl;
}

找到 用户名所在的行后, 我 直接把 用户名 所在的 下一行 作为 聊天内容,但其实 聊天内容里面 可以换行。

2、

如果 聊天 内容 里面 出现 用户名,会 误以为 是 用户名 所在的行,把这行输出 并把 下一行 输出。

特定用户QQ群聊天记录导出的实现的更多相关文章

  1. QQ群聊天记录文件分割

    嗯,如题 是个蛋疼物 目前QQ的聊天记录导出功能很让人郁闷 三种聊天记录格式的导出 1  TXT   没图 2  BAK  只能再导入QQ使用 3  MHT 有图有字,缺点是一旦聊天记录很多,文件体积 ...

  2. 使用 R 语言挖掘 QQ 群聊天记录

    1.获取数据 从 QQ 消息管理器中导出消息记录,保存的文本类型选择 txt 文件.这里获取的是某群从 2016-04-18 到 2016-05-07 期间的聊天记录,记录样本如下所示. 消息记录(此 ...

  3. 一梦江湖费六年——QQ群聊天分析

    本文结构: 一.那些年我们加过的QQ群 二.数据读入和整理(一)--来自蓝翔的挖掘机 二.数据读入和整理(二)--你不知道的事 三.聊天宏观(1)--寤寐思服 三.聊天宏观(2)日月篇 三.聊天宏观( ...

  4. 安卓QQ聊天记录导出、备份完全攻略

    发到知乎竟然被删掉,我也不知道我到底违反了哪条.唉,别人的毕竟是别人的.虽然博客园也是别人的 前言 我对聊天记录的备份比较执着,也在这上面折腾过不少.碰到过不少令人头疼的麻烦,在这里分享一下经验. 关 ...

  5. 编写Java程序,使用 Socket类模拟用户加入 QQ 群时,QQ 小冰发送欢迎消息的场景(用户充当客户端,QQ 小冰充当服务端)

    查看本章节 查看作业目录 需求说明: 小冰是微软公司研发的人工智能机器人,被腾讯公司加入 QQ 群后,立即受到千万网友的喜爱.现在使用 Socket类模拟用户加入 QQ 群时,QQ 小冰发送欢迎消息的 ...

  6. 前端资料QQ群交流

    转:https://github.com/jsfront/src/blob/master/qq.md 这本来是我QQ群内部的一份公共约定的日常交流规则,后来得到大伙的一致认可,并用实际行动来捍卫它,使 ...

  7. 关于iOS特定设别推送(特定用户推送)【原】

    在这里,我就不哆嗦如何制作推送证书之类的了,网上一搜一大堆. 我们现在很多开发者的推送,就是集成第三方的推送SDK,然后通过第三方的推送平台帮我们进行推送.其实,这种推送(如JPush),一般只能广播 ...

  8. 我们是怎么管理QQ群的

    文章背景:腾讯平台上的qq群数以千万百万计,但99%的在吹水扯蛋,从早上的问好开始,到晚上的晚安,无一不浪费青春之时间,看之痛心,无力改变,只好自己建了一个,希望能以此来改变群内交流的氛围或环境. 以 ...

  9. 关于玩QQ消息导入导出功能的感想!

    今天玩了一下QQ的导入导出聊天记录的功能,感觉自己有些白痴,因为作为一个软件开发人员对自己平时使用的软件的功能掌握的不够,别说其他的任何东西了就连功能性的操作有些也不知道更别说熟练或精通了,这不是一个 ...

随机推荐

  1. 为什么arcgis里,鼠标的图标都变成放大镜不能用了

    做作业做到一半,鼠标的图标就只有放大镜了,不管是点箭头还是作图工具都没用,手抓的也没用,只剩下放大镜的功能和图标了,这是怎么一回事啊?种情况我碰到过几次,具体原因不清楚,但是解决方法是有的:把你的数据 ...

  2. 转载:Restore SQL Server database and overwrite existing database

    转载自:https://www.mssqltips.com/sqlservertutorial/121/restore-sql-server-database-and-overwrite-existi ...

  3. linux 基本命令 [转]

    linux 基本命令 1.ls  (list 显示当前目录下文件和目录 ls -l 详细显示 =ll ) [root@linux ~]# ls [-aAdfFhilRS] 目录名称 [root@lin ...

  4. oracle 中将字符转换为blob 类型

    示例如下: select id,mblx,mbmc,TO_BLOB(UTL_RAW.CAST_TO_RAW(mbsj))mbsj,qyid,qycode from tempuser.temp_cwht ...

  5. submit text 插件安装教程

    特注:import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); o ...

  6. 【转载】Android推送方案分析(MQTT/XMPP/GCM)

    http://m.oschina.net/blog/82059 本文主旨在于,对目前Android平台上最主流的几种消息推送方案进行分析和对比,比较客观地反映出这些推送方案的优缺点,帮助大家选择最合适 ...

  7. android 使用两个surfaceview 在摄像机画面上绘图

    转载自http://blog.csdn.net/jesse__zhong/article/details/24934083 使用双surface,将第一个设置为透明背景,在摄像机上绘制图像,纠结搞了一 ...

  8. Android Timer用法

    Android考虑到线程安全问题,不允许在线程中执行UI线程,在Android中,有一个类:android.os.Handler,这个可以实现各处线程间的消息传递.先看段代码,这个实例化了一个Hand ...

  9. 在WCF中使用Flag Enumerations

      请看MSDN示例: [DataContract][Flags] public enum CarFeatures {     None = 0,     [EnumMember]     AirCo ...

  10. 忍者无敌-实例讲解Cocos2d-x瓦片地图

    实例比较简单,如图所示,地图上有一个忍者精灵,玩家点击他周围的上.下.左.右,他能够向这个方向行走.当他遇到障碍物后是无法穿越的,障碍物是除了草地以为部分,包括了:树.山.河流等. 忍者实例地图(TO ...