设为首页 加入收藏

TOP

3.6 C++(3)
2013-10-07 14:27:17 来源: 作者: 【 】 浏览:64
Tags:3.6

The main routine initializes the prefix, reads the input(from standard input, called cin in the C++(www.cppentry.com) iostream library), adds a tail, and generates the output, exactly as in the earlier versions:

图3.6  C++(www.cppentry.com)(2)  

The function build uses the iostream library to read the input one word at a time:

图3.6  C++(www.cppentry.com)(3)   

The string buf will grow as necessary to handle input words of arbitrary length.

The add function shows more of the advantages of using the STL:

图3.6  C++(www.cppentry.com)(4)    

Quite a bit is going on under these apparently simple statements.The map container overloads subscripting (the [] operator) to behave as a lookup operation. The expression statetab [prefix] does a lookup in statetab with prefix as key and returns a reference to the desired entry; the vector is created if it does not exist already. The push_back member functions of vector and deque push a new string onto the back end of the vector or deque; pop_front pops the first element off the deque.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇3.6 C++(4) 下一篇3.6 C++(2)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: