// map_tranc.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <map>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
map<string, string> trans_map;
string key,value;
// if(argc != 3)
// {
// throw runtime_error("wrong number of arguments\n");
// }
ifstream map_file("map.txt");
if( !map_file )
{
throw runtime_error("no transformation file\n");
}
while( map_file >> key >> value)
{
trans_map.insert(make_pair(key,value));
}
ifstream input("input.txt");
if(!input)
{
throw runtime_error("no input file\n");
}
string line;
while(getline(input,line))
{
istringstream stream(line);
string word;
bool firstword = true;
while( stream >> word )
{
map<string,string>::const_iterator map_it = trans_map.find(word);
if(map_it != trans_map.end())
{
word = map_it->second;
if(firstword)
firstword = false;
else
cout << " ";
cout << word;
}
}
cout << endl;
}
return 0;
}
input.txt
nah i sez tanx cuz i wuz pos to
not cuz i wuz gratz
map.txt
'em them
cuz because
gratz grateful
i I
nah no
pos supposed
sez said
tanx thanks
wuz was