C++ Map Source
/*
* =====================================================================================
*
* 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相关推荐
- Source Map的原理探究
摘要: Source Map很神奇,它的原理挺复杂的- 原文:source map 的原理探究 地址:https://www.cnblogs.com/Wayou/p/understanding_fro ...
- webpack之source map
webpack之source map 前言 一.什么是source map 二.在webpack中启用source map 三.关于source map的各种模式 前言 通过构建编译之类的操作,我们可 ...
- Source Map介绍 -浏览器篇
Source Map介绍 - 浏览器篇 Source Map介绍 浏览器source map source map 使用介绍和原理 浏览器支持 参考链接 Source Map介绍 在做网站性能优化的时 ...
- Webpack——调试工具Source Map
Source Map是一个信息文件,里面存储这位置信息 并不是我们生活中的卫星定位信息,是指定代码的位置信息,可以清晰的获取到指定代码所处在的行数 为什么需要Source Map呢?难道我们打开终端看 ...
- webpack的source map
文章目录 demo 代码结构 原始源代码 编译后的代码 source map source map是什么 启用source map devtool 值为source-map 值为inline-sour ...
- jquery.min.map 404 (Not Found)出错的原因及解决办法
Chrome 更新后出现了 jquery.min.map 404 (Not Found) 的信息 这个到底是什么东西?查询了一下,得到了以下资料 JQuery 官方解释 摘录一下內容 从 jQuer ...
- Java树形转扁平_多层嵌套map对象转扁平化map
将深度嵌套的map对象转换为扁平化的map对象输出. import org.apache.commons.lang3.StringUtils; import java.util.HashMap; im ...
- RxSwift之深入解析map操作符的底层实现
一.map 操作符的使用 map 操作符将源 Observable 的每个元素转换一遍,然后返回含有转换结果的 Observable: 现有如下示例: Observable<Int>.of ...
- 导致jquery.min.map 404 (Not Found)错误的原因
1.报错找不到jquery.min.map 当打开引入jQuery脚本的页面时,在Chrome的控制台中报了"GET http://localhost/libs/jquery.min.map ...
最新文章
- R语言基于日期范围筛选数据实战(Subset by a Date Range):日期范围之内的数据、日期范围之外的数据、日期之后的数据、日期之前的数据
- echarts - geo 绘制无数据区域的区域
- Spark入门实战系列--2.Spark编译与部署(下)--Spark编译安装
- HALCON基于形状匹配详解
- docker探索-docker安装运行tomcat(六)
- netty的编解码、粘包拆包问题、心跳检测机制原理
- mysql @符号_quot;Incorrect string value quot; mysql 乱码 my插入emoji Yii2
- Effective C# 摘录(3) - 使用C#表达设计
- 手机快充功能到底是充电头的功劳还是线的功劳?
- 【windows10】对系统盘瘦身
- Java开发常见专业术语
- 在Docker里部署ReviewBoard4.0-RC
- 前端三大框架React、Vue、Angular简述
- oracle 变更字段名称_oracle怎么修改字段名?
- 【CF633H】Fibonacci-ish II(权值线段树)(莫队)
- js 去除数组里的空值
- 如何在Microsoft Word里面插入图片作为背景?
- 技巧1——怎样查看linux发行版本名称和版本号?
- idea设置java-google-style
- Hadoop入门案例WordCount