C++ 编程题练习(9-2)
来源:互联网 发布:安庆网络问政平台2017 编辑:程序博客网 时间:2024/06/06 03:51
C++ 编程题练习
来源:coursera c++ pku 第9周编程作业
一、题目
描述:
写一个自己的 CMyistream_iterator 模板,使之能和 istream_iterator 模板达到一样的效果。
输入:
79 90 20 hello me
输出:
79
79,90,20
hello,me
#include <iostream>#include <string>using namespace std;// 在此处补充你的代码int main(){ CMyistream_iterator<int> inputInt(cin); int n1,n2,n3; n1 = * inputInt; //读入 n1 int tmp = * inputInt; cout << tmp << endl; inputInt ++; n2 = * inputInt; //读入 n2 inputInt ++; n3 = * inputInt; //读入 n3 cout << n1 << "," << n2<< "," << n3 << endl; CMyistream_iterator<string> inputStr(cin); string s1,s2; s1 = * inputStr; inputStr ++; s2 = * inputStr; cout << s1 << "," << s2 << endl; return 0;}
二、程序
template <class T>class CMyistream_iterator{ private: istream & is; T value; public: CMyistream_iterator(istream & is):is(is) { is>>value; } void operator++(int) { is>>value; } T & operator*(){ return value; }};
0 0
- C语言编程(练习2:函数 )
- C++ 编程题练习(9-2)
- C Primer Plus 第六章 编程练习 9-16题
- C Primer Plus 第九章 编程练习 1-9题
- C Primer Plus 第三章 编程练习 2-7题
- C语言编程(练习9:数组与指针)
- C语言编程(练习2:循环,三大循环结构 )
- C语言编程(练习2:分支和跳转 )
- C语言编程(练习2:字符输入和输出 )
- C语言编程(练习2:数组和指针)
- C语言编程(练习2:字符串与字符串数组)
- C primer plus(编程练习)file-9.11-2
- C primer plus(编程练习)file-2.12-2
- C primer plus(编程练习)file-3.11-2
- C primer plus(编程练习)file-4.8-2
- 编程练习(2)
- 编程练习(2)
- 编程练习(2)
- dispatch_barrier_async一些用法
- MySQL连接方式
- 让eclipse读取ftl格式的文件
- 栈区和堆区内存分配区别
- 同步VS异步 阻塞VS非阻塞
- C++ 编程题练习(9-2)
- javaScript基础知识
- Python实现mapreduce程序
- 安装node-sass遇到的各种各样的问题及解决
- ibatis $ 和 # 的区别
- 使用scanf函数时应该注意的问题
- SAP 请勿打扰
- CSS经验分享
- 从mms源码看IM应用的架构<二>