日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++ Map Source

發布時間:2025/4/14 c/c++ 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。