《Essential C++》笔记三(3)、使用iostream iterators
2013-10-03 13:22
274 查看
Essential C++书中,给了一段关于iosteram iterators的例程,如下所示:
在输入的过程中,出现了一个问题,就是控制台不断要求输入,好像进入死循环,对于这个问题,http://wenku.baidu.com/view/91f2f2eff8c75fbfc77db2f5.html,给出了一些解释。
对于书中给出的程序来说,如果单步调试,会发现,在
两个语句中,都再次调用了cin,解决的办法就是输入一串字符串后,当要求再次输入时,点击“Ctrl+Z”,人为输入EOF结束符。
#include <iostream> #include <iterator> #include <algorithm> #include <vector> #include <string> using namespace std; int main() { istream_iterator< string > is( cin ); istream_iterator< string > eof; vector< string > text; copy( is, eof, back_inserter( text )); sort( text.begin(), text.end() ); ostream_iterator<string> os( cout, " " ); copy( text.begin(), text.end(), os ); }
在输入的过程中,出现了一个问题,就是控制台不断要求输入,好像进入死循环,对于这个问题,http://wenku.baidu.com/view/91f2f2eff8c75fbfc77db2f5.html,给出了一些解释。
对于书中给出的程序来说,如果单步调试,会发现,在
istream_iterator< string > is( cin ); copy( is, eof, back_inserter( text ));
两个语句中,都再次调用了cin,解决的办法就是输入一串字符串后,当要求再次输入时,点击“Ctrl+Z”,人为输入EOF结束符。
相关文章推荐
- 《Essential C++》笔记三(1)、使用泛型算法
- (原)使用vectot的.end()报错:iterators incompatible
- 【c++系列】iostream iterators
- c++ stl iostream 使用笔记三
- iostream使用技巧
- 使用boost iostream写文件
- 编译C++的时候系统提示【 “#include “iostream.h”: 在查找预编译头使用时跳过 】
- 002_013 Python 使用C++类的iostream语法
- c++ stl iostream 使用笔记一
- 20141204-关于使用C++标准输入输出库:iostream的一点思考
- C++标准库 之 iostream库的学习笔记(三) ifstream类的使用和介绍
- 使用iostream与iostream.h区别 关于C++中头文件使用
- iostream使用时注意事项
- iostream 的使用方法
- iostream iterator使用
- C++的iostream标准库介绍+使用详解(转)
- C++的iostream标准库介绍+使用详解
- #include<iostream>和#include<iostream.h>区别使用
- iostream/fstream中的输入输出流指针的绑定,tie函数的使用。
- 《Essential C++》笔记三(2)、泛型编程风格