利用map容器中统计文件中相同字符串的个数
来源:互联网 发布:在职软件工程硕士2018 编辑:程序博客网 时间:2024/05/19 16:51
//c++ 统计文件中相同字符串的个数
#include <iostream>
#include <string>#include <map>
#include <fstream>
using namespace std;
int main(int argc,char*argv[])
{
map<string, int> mapA;
ifstream myfile;
//打开文件
myfile.open("1.txt", ios::in);
if (!myfile)
{
cout << "文件读错误";
system("pause");
exit(1);
}
char c[1000];
while (myfile.getline(c, 9999))
{
//cout << c << "-------------" << mapA.count(c) << endl;
if (mapA.count(c) == 0) //不存在
{
mapA.insert(pair<string, int>(c, 1));
}
else //存在
{
mapA[c]++;
}
memset(c, 0, sizeof(c));
}
myfile.close();
for (map<string, int>::iterator it = mapA.begin(); it != mapA.end(); it++)
{
cout << "key = " << it->first << "\tvalue=" << it->second <<endl;
}
cin.get();
return 0;
}
1 0
- 利用map容器中统计文件中相同字符串的个数
- excel中统计一列中相同内容的个数
- Matlab中统计矩阵中相同元素的个数
- Matlab中统计矩阵中相同元素的个数
- Matlab中统计矩阵中相同元素的个数
- Matlab中统计矩阵中相同元素的个数的方法
- 如何在MATLAB中统计数组中相同元素的个数?
- 字符串中统计单词个数
- 母字符串中统计子字符串的个数
- 在字符串中统计特定字符串的个数
- java中统计字符串中汉字,英文,数字,特殊符号个数
- Java中统计文章字符串字符个数的代码实现
- vf中统计表格中纪录的个数
- sql中统计一列中重复的数据个数
- Java中统计字符串中各字符出现的次数
- 在Vim中统计单词的个数
- HM中统计LCU的个数
- 二进制中统计1的个数
- SpringMVC,Mybatis,FreeMarker连接mycat示例(一)
- itoa、atoi
- 有符号数除以非-2的幂(MagicNumber为负)
- C++ getline()和get()
- 电路设计_红外遥控设计经验
- 利用map容器中统计文件中相同字符串的个数
- 3D图形渲染管线
- 深入理解ButterKnife源码并掌握原理(一)
- 360校招编程题:内存管理
- Python3 获取异常的信息和traceback(实现类似PyErr_Print功能)
- 手机中常用的TELECOM 层的协议
- 关于cmd无法打开mysql服务的解决方法
- LibGdx文档译读(二)ApplicationListener接口
- 电路与Multisim Multisim中的电路图必须要接地