c++_primer_exercise_11333435

来源:互联网 发布:淘宝发布话费充值 编辑:程序博客网 时间:2024/05/19 02:27

Write a program that, given one string, transforms it into another. The input to our program is two files. The first file contains rules that we will use to transform the text in the second file. Each rule consists of a word that might be in the input file and a phrase to use in its place. The idea is that when ever the first word appears in the input, we will replace it with the corresponding phrase. The second file contains the text to transform.


--------------------------------------------------------------------------------------------


Exercise 11.34: What would happen if we used the subscript operator instead of find in the transform function?

If the key is not in the map, then subscript inserts an element with that key. It is not what we expected.


Exercise 11.35: 

As to the first version that we used in the code above, if a word does appear multiple times, our loop will put the first corresponding phrase into trans_map.

As to the second version, if a word does appear multiple times, our loop will put the first corresponding phrase into trans_map.(For map and set, the element is inserted only if an element with the given key is not already in.)

0 0
原创粉丝点击