/*
 * =====================================================================================
 *
 *       Filename:  main.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2012年12月18日 13时29分04秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */
#include<iostream>
#include "main.h"
#include <string>
#include <map>
using namespace std;
int main()
{
char both[255] = "./both.txt";
char neg[255] = "./negative.txt";
char pos[255]= "./positive.txt";
map<string, int> both_map;//map is a variable, but not a pointer
map<string ,int> neg_map;
map<string ,int> pos_map;

readtohash(both, &both_map);
readtohash(neg, &neg_map,1);
readtohash(pos, &pos_map,1);
cout<<"The Both Map is:"<<both_map.size()<<endl;
cout<<"The Neg Map is:"<<neg_map.size()<<endl;
cout<<"The Pos Map is:"<<pos_map.size()<<endl;
merge(&both_map, &neg_map, &pos_map);
writefromhash("./new_negative.txt", &neg_map);
writefromhash("./new_positve.txt", &pos_map);

}

/*
 * =====================================================================================
 *
 *       Filename:  main.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2012年12月18日 16时54分59秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */
#include <iostream>
#include <iomanip>
#include <fstream>
#include <map>
using namespace std;
void readtohash(char *path, map<string, int> *hash_map) {
//char buffer[256];
ifstream myfile (path);
if (!myfile) {
cout<< "Unbale to open"<<endl;
}
  while (myfile.peek() != EOF) {
string str;
int sign =  -5;
myfile>>str>>sign; //ch is for /n
(*hash_map)[str] = sign; // the privilege of square bracket[] if lower than *
// cout<<str<<sign<<endl;

}
myfile.close();
 }

void readtohash(char *path, map<string, int> *hash_map, int value) {
ifstream myfile (path);
if (!myfile) {
cout<< "Unbale to open"<<endl;
}
  while (myfile.peek() != EOF) {
string str;
myfile>>str;
(*hash_map)[str] = value; // the privilege of square bracket[] if lower than *

}
myfile.close();
 }
void merge(map<string, int> *both_map, map<string, int> *neg_map, map<string, int> *pos_map) {
map<string, int>::iterator it;
it = (*both_map).begin();
while (it != (*both_map).end()) {
// cout<< it->first<<";";
// cout<< it->second<<endl;
if (it->second == 1)
{
(*neg_map).erase(it->first);
}
else if(it->second == -1)
{
(*pos_map).erase(it->first);
}
else {
(*neg_map).erase(it->first);
(*pos_map).erase(it->first);
}
it++;
}
}
void writefromhash(char* path, map<string, int> *hash_map) {
map<string, int >::iterator it;
it = (*hash_map).begin();
ofstream outfile (path);
while (it != (*hash_map).end()) {
outfile<<it->first<<endl;
it++;
}
}

/*
 * =====================================================================================
 *
 *       Filename:  main.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2012年12月18日 13时28分06秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */
#ifndef _main_h
#define _main_h
#include <map>
#include <string>
using namespace std;
void readtohash(char *path, map<string, int> *hash_map);
void readtohash(char *path, map<string, int> *hash_map, int value);
void merge(map<string, int> *both_map, map<string, int> *neg_map, map<string, int> *pos_map);
void writefromhash(char *path, map<string, int> *hash_map);
#endif

C++ Map Source相关推荐

  1. Source Map的原理探究

    摘要: Source Map很神奇,它的原理挺复杂的- 原文:source map 的原理探究 地址:https://www.cnblogs.com/Wayou/p/understanding_fro ...

  2. webpack之source map

    webpack之source map 前言 一.什么是source map 二.在webpack中启用source map 三.关于source map的各种模式 前言 通过构建编译之类的操作,我们可 ...

  3. Source Map介绍 -浏览器篇

    Source Map介绍 - 浏览器篇 Source Map介绍 浏览器source map source map 使用介绍和原理 浏览器支持 参考链接 Source Map介绍 在做网站性能优化的时 ...

  4. Webpack——调试工具Source Map

    Source Map是一个信息文件,里面存储这位置信息 并不是我们生活中的卫星定位信息,是指定代码的位置信息,可以清晰的获取到指定代码所处在的行数 为什么需要Source Map呢?难道我们打开终端看 ...

  5. webpack的source map

    文章目录 demo 代码结构 原始源代码 编译后的代码 source map source map是什么 启用source map devtool 值为source-map 值为inline-sour ...

  6. jquery.min.map 404 (Not Found)出错的原因及解决办法

    Chrome 更新后出现了 jquery.min.map 404  (Not Found) 的信息 这个到底是什么东西?查询了一下,得到了以下资料 JQuery 官方解释 摘录一下內容 从 jQuer ...

  7. Java树形转扁平_多层嵌套map对象转扁平化map

    将深度嵌套的map对象转换为扁平化的map对象输出. import org.apache.commons.lang3.StringUtils; import java.util.HashMap; im ...

  8. RxSwift之深入解析map操作符的底层实现

    一.map 操作符的使用 map 操作符将源 Observable 的每个元素转换一遍,然后返回含有转换结果的 Observable: 现有如下示例: Observable<Int>.of ...

  9. 导致jquery.min.map 404 (Not Found)错误的原因

    1.报错找不到jquery.min.map 当打开引入jQuery脚本的页面时,在Chrome的控制台中报了"GET http://localhost/libs/jquery.min.map ...

最新文章

  1. R语言基于日期范围筛选数据实战(Subset by a Date Range):日期范围之内的数据、日期范围之外的数据、日期之后的数据、日期之前的数据
  2. echarts - geo 绘制无数据区域的区域
  3. Spark入门实战系列--2.Spark编译与部署(下)--Spark编译安装
  4. HALCON基于形状匹配详解
  5. docker探索-docker安装运行tomcat(六)
  6. netty的编解码、粘包拆包问题、心跳检测机制原理
  7. mysql @符号_quot;Incorrect string value quot; mysql 乱码 my插入emoji Yii2
  8. Effective C# 摘录(3) - 使用C#表达设计
  9. 手机快充功能到底是充电头的功劳还是线的功劳?
  10. 【windows10】对系统盘瘦身
  11. Java开发常见专业术语
  12. 在Docker里部署ReviewBoard4.0-RC
  13. 前端三大框架React、Vue、Angular简述
  14. oracle 变更字段名称_oracle怎么修改字段名?
  15. 【CF633H】Fibonacci-ish II(权值线段树)(莫队)
  16. js 去除数组里的空值
  17. 如何在Microsoft Word里面插入图片作为背景?
  18. 技巧1——怎样查看linux发行版本名称和版本号?
  19. idea设置java-google-style
  20. Hadoop入门案例WordCount

热门文章

  1. cvpr 2017 re-id papers
  2. 离线轻量级大数据平台Spark之MLib机器学习库SVM实例
  3. 基于快速原型模型建立商业呼叫中心SPOMP的应用研究
  4. 开关电源怎么测试文波_示波器测试开关电源纹波的方法
  5. 使用Spring Initializer快速创建Spring Boot项目
  6. Iterator迭代器
  7. 解决导航守卫router.beforeResolve使用不了this.$store
  8. EEPROM存储器--AT24CXX
  9. 九度-1463-招聘会
  10. C++ Vector用法深入剖析