c++ prime 5 ex11_4

代码如下

// ex11_4_word_transform.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include <map>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include <sstream> using std::map; using std::string; using std::vector;
using std::ifstream; using std::cout; using std::endl;
using std::getline;
using std::runtime_error; using std::istringstream; map<string, string> buildMap(ifstream &map_file)
{
map<string, string> trans_map; // holds the transformations
string key; // a word to transform
string value; // phrase to use instead
// read the first word into key and the rest of the line into value
while (map_file >> key && getline(map_file, value))
if (value.size() > ) // check that there is a transformation
trans_map[key] = value.substr(); // skip leading space
else
throw runtime_error("no rule for " + key);
return trans_map;
} const string &
transform(const string &s, const map<string, string> &m)
{
// the actual map work; this part is the heart of the program
auto map_it = m.find(s);
// if this word is in the transformation map
if (map_it != m.cend())
return map_it->second; // use the replacement word
else
return s; // otherwise return the original unchanged
} // first argument is the transformations file;
// second is file to transform
void word_transform(ifstream &map_file, ifstream &input)
{
auto trans_map = buildMap(map_file); // store the transformations // for debugging purposes print the map after its built
cout << "Here is our transformation map: \n\n";
for (auto entry : trans_map)
cout << "key: " << entry.first
<< "\tvalue: " << entry.second << endl;
cout << "\n\n"; // do the transformation of the given text
string text; // hold each line from the input
while (getline(input, text)) { // read a line of input
istringstream stream(text); // read each word
string word;
bool firstword = true; // controls whether a space is printed
while (stream >> word) {
if (firstword)
firstword = false;
else
cout << " "; // print a space between words
// transform returns its first argument or its transformation
cout << transform(word, trans_map); // print the output
}
cout << endl; // done with this line of input
}
} int main(int argc, char **argv)
{
// open and check both files
//if (argc != 3)
// throw runtime_error("wrong number of arguments"); argv[] = "……";
argv[] = "……";
ifstream map_file(argv[]); // open transformation file
if (!map_file) // check that open succeeded
throw runtime_error("no transformation file"); ifstream input(argv[]); // open file of text to transform
if (!input) // check that open succeeded
throw runtime_error("no input file"); word_transform(map_file, input); system("pause"); return ; // exiting main will automatically close the files
}

1.关于main函数中的三个参数 ,ref: int main(int argc,char* argv[])详解

char  *argv[]是一个字符数组,其大小是int  argc,主要用于命令行参数  argv[]  参数,数组里每个元素代表一个参数;
比如你输入   
   test   a.c   b.c   t.c   
   则   
   argc   =   4   
    
   argv[0]   =   "test"   
   argv[1]   =   "a.c"   
   argv[2]   =   "b.c"   
   argv[3]   =   "t.c"
--------------------------------------------------------------------------------------------  
argc记录了用户在运行程序的命令行中输入的参数的个数。   
arg[]指向的数组中至少有一个字符指针,即arg[0].他通常指向程序中的可执行文件的文件名。在有些版本的编译器中还包括程序文件所在的路径。
-------------------------------------------------------------------------
在调用一个可执行程序时,某些情况下需要向程序传递参数。如我们可以在控制台中键notepad.exe,
回车后将执行记事本程序。如果我们希望在打开notepad时同时打开一个文本文件,可以在notepad.exe 后面跟上文件的路径和名字,如notepad.exe   example.txt(文件在当前路径)。   
    
   那么程序中如何能得到这些输入参数呢?这个工作是编译器帮我们完成的,编译器将输入参数的信息
放入main函数的参数列表中。   
    
   main函数的参数列表保存了输入参数的信息,第一个参数argc记录了输入参数的个数,第二个参数是字符串数组的,字符串数组的每个单元是char*类型的,指向一个c风格字符串。   
   以notepad.exe   example.txt为例   
   argc是2,就是说argv数组中有两个有效单元   
   第一单元指向的字符串是"notepad.exe"   
   第二单元指向的字符串是"example.txt"   
    
   argv数组中的第一个单元指向的字符串总是可执行程序的名字,以后的单元指向的字符串依次是程序调用时的参数。   
    
   这个赋值过程是编译器完成的,我们只需要读出数据就可以了。

2.读写文件,ref:C++文件读写详解(ofstream,ifstream,fstream)

3. getline

ref:cin 输入空格符和 getline() 忽略开头换行符

C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法


用cmd执行

argv[1]是exe的转义字符路径,argv[2]是 rules文件的转义字符路径,argv[3]是待转换文件的转义字符路径。

												

C++ 编写的解码器小程序 map的更多相关文章

  1. 微信小程序----map组件实现检索【定位位置】周边的POI

    效果图 实现方法 地图采用微信小程序提供的map组件: 周边的数据坐标点通过高德地图提供的API接口,获取定位位置的周边或者指定位置周边的数据. WXML <view class="m ...

  2. 小程序map地图多点定位

    最近需求有一个类似共享单车查看附近单车的功能,看了看小程序map api对多点定位显示描述的不怎么清晰.显示定位数组添加多个时就不显示了.踩了几个坑写了几个方法.最终弄出来了.有问题建议欢迎留言. h ...

  3. 微信小程序map地图的一些使用注意事项

    1.小程序组件map,在微信7.0.4以上(不包括7.0.4)层级问题官方已作更新,可在map上随意添加任何标签使用z-index即可:微信7.0.4版本以下map组件层级默认是最高的,只能使用官方提 ...

  4. 小程序 map组件问题 cover-view问题

    使用小程序的组件map时 在开发者工具上一切顺利 但是在真机预览时 发现地图的层级是最高的 任何标签都覆盖不了它 调整z-index值并没有什么效果 原因是 微信小程序的map.video.canva ...

  5. 微信小程序map组件z-index的层级问题

    说起微信小程序的map组件,可以说是良心之作了,一个组件解决了所以接入地图的所有麻烦,但是在实际小程序的试用过程中还是存在点问题的.如下情景:刚开始接入map组件的时候是在微信开发工具的模拟器上预览的 ...

  6. 微信小程序~map组件z-index无效

    因项目需要,以map为背景,上面悬浮有其他组件.微信开发者工具测试时一切正常,但是真机测试时地图组件却把所有的组件覆盖,检查z-index设置,一切正常,地图组件层级也在这些组件的下面,为什么会被覆盖 ...

  7. 百度小程序-map组件定位

    给客户开发一个百度小程序,有个地图定位显示.百度小程序内置的api地图是不准的,通过百度一下,查询到坐标偏移算法公式,自己项目中使用,手机测试坐标已经正常显示! 经纬度,通过百度坐标拾取器拾取到! . ...

  8. 小程序map学习:使用map获取当前位置并显示出来

    在小程序开发的过程中,我碰到过一个做map的需求,在我开发的时候我碰到了一些问题,这里总结出来,给大家一些解决方法. 简易小程序dome下载 代码片段分享: js部分: var amapFile = ...

  9. 微信小程序-----安装,编写第一个小程序和运行到手机端

    第一步: 微信公众平台注册账号,并选择小程序,网址:mp.weixin.qq.com 填写相关信息,如:主体类型(个人或者企业) AppID  在开发中都是用的到的,服务器域名在网络请求也是用的到的. ...

随机推荐

  1. (转)AIX下的MPIO、RDAC、SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系)

    AIX下的MPIO.RDAC.SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系) 原文:http://blog.163.com/huangbao_007 ...

  2. (转)blkid命令 获取文件系统类型、UUID

    blkid命令 获取文件系统类型.UUID  原文:http://www.cnblogs.com/dkblog/archive/2011/08/30/2159630.html 在Linux下可以使用b ...

  3. jade 入门

    推荐网站: jade官网 html在线转换为jade 参考文章1 参考文章2     node的模板常用的有两个,一个是ejs,另外一个就是jade,相对来说,ejs更容易理解,像原生的html,很多 ...

  4. JavaScript操作符(=?,)优先级

    JavaScript操作符优先级: 关于最后3个运算符的优先级比较,下面通过一个实例来具体说明: var a,b,c; a = 3,4,5; b = a--,--a,a; c = a ? b++ : ...

  5. GitKraken使用教程-基础部分(2)

    3. 修改用户名 为了方便项目中代码的管理,需要重新编辑用户名. 点击右上角的图像即可看到如下图 3‑1所示的下拉菜单,鼠标悬于Profile上,会出现一个Edit按钮. 图 3‑1 编辑个人信息 点 ...

  6. 拿到返回值,Callable示例

  7. deployment删除后,副本集未删除,解决之道

    在删除的body上加上,body.setPropagationPolicy("Foreground");就可以删除deployment的同时连同副本集一同删除.

  8. java使用jdbc连接数据库步骤

    确定连接的数据库类型<mysql,oracle,db2,moangdb,sqlservlet> 下载数据库的驱动(http://mvnrepository.org),并把jar包添加到项目 ...

  9. CDSN博客第一天

    CDSN博客第一天 今天是CSDN写博客的第一天. 2017/2/11 13:05:45

  10. jQuery中的CSS-DOM操作

    html代码 <p style="color:blue;">武汉PHP培训-武汉长乐教育</p> css()方法 $("p").css( ...