c++单词转换程序
c++primer 第十二章的单词转换程序运行后出现debug

c++primer 第十二章的单词转换程序运行后出现debug
// 单词转换.cpp
#include<iostream>
#include<map>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
ifstream& open_file(ifstream& in,const string&file);
int main(int argc ,char **argv)
{
map<string,string> trans_map;
string key,value;
if(argc!=3)
throw runtime_error("wrong number of arguments");
ifstream map_file;
if(!open_file(map_file,argv[1]))
throw runtime_error("no transformation file");
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
if(!open_file(input,argv[2]))
throw runtime_error("no input file");
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;
}
ifstream& open_file(ifstream& in,const string&file)
{
in.close();
in.open(file.c_str());
return in;
}

c++primer 第十二章的单词转换程序运行后出现debug
// 单词转换.cpp
#include<iostream>
#include<map>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
ifstream& open_file(ifstream& in,const string&file);
int main(int argc ,char **argv)
{
map<string,string> trans_map;
string key,value;
if(argc!=3)
throw runtime_error("wrong number of arguments");
ifstream map_file;
if(!open_file(map_file,argv[1]))
throw runtime_error("no transformation file");
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
if(!open_file(input,argv[2]))
throw runtime_error("no input file");
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;
}
ifstream& open_file(ifstream& in,const string&file)
{
in.close();
in.open(file.c_str());
return in;
}
...全文
相关推荐
简单C++程序
简单的C++应用,适用于初学者,有需要的就下载吧
noip-2011-c++题解.docx
NOIP的系列试题答案资源,整理合集,有2009~2017的试题与答案,需要资源的同鞋么们可以下载哦
cpp代码-语料字典1
cpp代码-语料字典1
用c++实现将文本每个单词首字母转换为大写
利用C++,读入一个英文文本,并将文本中的每个英文单词首字母大写。本程序练习了从一个文本中读入流,用到了fstream流。 在文本的转换过程中,用到了isalpha()——是否是字母,toupper()——转换为大写字符 这两个函数(针对string对象的单个字符的操作。类似的操作还有isalnum()——是否是字母或数字,iscntrl()——是否是控制字符, isdigit()——是否是数字,isgraph()——是否不是空格,但可以打印,islower()——是否是小写字母, isprint()——是否是可以打印的字符,ispunct()——是否是标点符号,isspace()——是否是空
单词的词法分析设计程序
通过设计、编制、调试一个具体的词法分析程序,加深对词法分析原理的理解,并掌握在对程序设计语言源程序进行扫描过程中将其分解为各类单词的词法分析方法。



