primer4 16.2
来源:互联网 发布:淘宝上差评多久消失 编辑:程序博客网 时间:2024/06/05 03:04
//编写一个函数模板,接受一个ostream引用和一个值,将该值写入流,用至少四种不同类型调用函数。//通过写至cout,写至文件和写至stringstream来测试#include<iostream>#include<tchar.h>#include<ostream>#include<fstream>#include<sstream>#include<cassert>using namespace std;template <typename t> inlinevoid testostream(ostream& os, t tval){os << tval;}int _tmain(int argc, _TCHAR* argv[]){//coutcout << "test of testostream(cout,6):\t";testostream(cout, 6);cout << "\n test of testostream(cout,true):\t";testostream(cout, true);cout << "\n test of testostream(cout,8.6):\t";testostream(cout, 8.6);cout << "\n test of testostream(cout,\"good\"):\t";testostream(cout, "good");cout << endl;//ofstreamofstream outfile;outfile.open("testof_ofstream.txt");assert(outfile);if (!outfile){return NULL;}cout << "\n\ttest of ofstream,please check the file just create.\n";testostream(outfile, "\n tset of testostream(outfile,6):\t");testostream(outfile, 6);testostream (outfile, "\n test of testostream(outfile,ture):\t");testostream(outfile, true);testostream(outfile, "\n test of testostream(outfile,8.6):\t");testostream(outfile, 8.6);testostream(outfile,"\n test of testostream(outfile,\"good\"):\t");outfile.close();cout << endl;//stringstreamstringstream oss;cout << "\n test of testosteam(oss,6)/(oss,8.6)/(oss,\"good\"):" << endl;testostream(oss, 6);testostream(oss, "\n");testostream(oss, true);testostream(oss, "\n");testostream(oss, 8.6);testostream(oss, "\n");testostream(oss, "good");testostream(oss, "\n");cout << oss.str() << endl;system("pause");return 0;}
阅读全文
0 0
- primer4 16.2
- C++Primer4笔记
- C++Primer4 笔记
- (转) C++Primer4 笔记
- C++Primer4.8练习。
- C++Primer4.32练习题
- C++Primer4.35练习题。
- C++ primer4 Chapter 7. Functions
- C++ Primer4 Chapter 12. Classes
- C++ primer4 Chapter 3. Library Types
- C++ Primer4 Chapter 8. The IO Library
- C++ Primer4 Chapter 9. Sequential Containers
- C++ Primer4 Chapter 2. Variables and Basic Types
- C++学习之泛型算法概述--摘自C++primer4
- 《C++Primer4》附录-标准库io库的使用
- 16.2
- 16.2
- 16.2
- 前端跨域解决方案
- 百度地图点聚合改造
- PCB设计软件
- springMVC拦截器处理ajax请求及数据返回
- Java基础笔记-反射
- primer4 16.2
- Python GUI编程(Tkinter)
- POJ 3667
- Vue基础
- 解决CentOS7下使用ifconfig命令无法查看inet地址
- Android Studio 打包 release 版本后无法安装的问题
- 使用canvas与png/svg等格式图片解决html异形按钮创建
- 每天一道LeetCode-----将字符串的连续相同的字符合并成一个字符后加个数
- 1.身份证号码校验