欢迎来到天天文库
浏览记录
ID:39546711
大小:94.50 KB
页数:9页
时间:2019-07-06
《C++Primer第16章-模板与泛型编程-部分选做习题答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、16章部分选做习题16.1编写一个模板返回形参的绝对值,至少用三种不同类型的值调用模板。注意:在16.3节讨论编译器怎样处理模板实例化之前,你应该将每个模板定义和该模板的所有使用放在同一文件中。//16.1_template.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#includetemplateinlineTabs(TtVal){returntVal>0?tVal:-1*tVal;}int_tmain(intargc,_TCHAR*argv[]){std::cout<<"
2、tabs(false)is:t"<3、。//#include"stdafx.h"#include#include#include#include#includeusingnamespacestd;templateinlinevoidtestOstream(ostream&os,TtVal){os<4、eam(cout,6);cout<<"TestoftestOstream(cout,true):t";testOstream(cout,true);cout<<"TestoftestOstream(cout,8.6):t";testOstream(cout,8.6);cout<<"TestoftestOstream(cout,"Good!"):t";testOstream(cout,"Good!");cout<5、m.txt");assert(outfile);if(!outfile){returnNULL;}cout<<"tTestofofstream,Pleasecheckthefilejustcreate.";testOstream(outfile,"TestoftestOstream(outfile,6):t");testOstream(outfile,6);testOstream(outfile,"TestoftestOstream(outfile,true):t");testOstream(outfile,true);test6、Ostream(outfile,"TestoftestOstream(outfile,8.6):t");testOstream(outfile,8.6);testOstream(outfile,"TestoftestOstream(outfile,"Good!"):t");testOstream(outfile,"Good!");outfile.close();cout<7、ss,8.6)/(oss,"Good!"):"<8、e时,传递用字符串字面值初始化的两个string对象。如果编写以下代码会发生什么?compare(“hi”,
3、。//#include"stdafx.h"#include#include#include#include#includeusingnamespacestd;templateinlinevoidtestOstream(ostream&os,TtVal){os<4、eam(cout,6);cout<<"TestoftestOstream(cout,true):t";testOstream(cout,true);cout<<"TestoftestOstream(cout,8.6):t";testOstream(cout,8.6);cout<<"TestoftestOstream(cout,"Good!"):t";testOstream(cout,"Good!");cout<5、m.txt");assert(outfile);if(!outfile){returnNULL;}cout<<"tTestofofstream,Pleasecheckthefilejustcreate.";testOstream(outfile,"TestoftestOstream(outfile,6):t");testOstream(outfile,6);testOstream(outfile,"TestoftestOstream(outfile,true):t");testOstream(outfile,true);test6、Ostream(outfile,"TestoftestOstream(outfile,8.6):t");testOstream(outfile,8.6);testOstream(outfile,"TestoftestOstream(outfile,"Good!"):t");testOstream(outfile,"Good!");outfile.close();cout<7、ss,8.6)/(oss,"Good!"):"<8、e时,传递用字符串字面值初始化的两个string对象。如果编写以下代码会发生什么?compare(“hi”,
4、eam(cout,6);cout<<"TestoftestOstream(cout,true):t";testOstream(cout,true);cout<<"TestoftestOstream(cout,8.6):t";testOstream(cout,8.6);cout<<"TestoftestOstream(cout,"Good!"):t";testOstream(cout,"Good!");cout<5、m.txt");assert(outfile);if(!outfile){returnNULL;}cout<<"tTestofofstream,Pleasecheckthefilejustcreate.";testOstream(outfile,"TestoftestOstream(outfile,6):t");testOstream(outfile,6);testOstream(outfile,"TestoftestOstream(outfile,true):t");testOstream(outfile,true);test6、Ostream(outfile,"TestoftestOstream(outfile,8.6):t");testOstream(outfile,8.6);testOstream(outfile,"TestoftestOstream(outfile,"Good!"):t");testOstream(outfile,"Good!");outfile.close();cout<7、ss,8.6)/(oss,"Good!"):"<8、e时,传递用字符串字面值初始化的两个string对象。如果编写以下代码会发生什么?compare(“hi”,
5、m.txt");assert(outfile);if(!outfile){returnNULL;}cout<<"tTestofofstream,Pleasecheckthefilejustcreate.";testOstream(outfile,"TestoftestOstream(outfile,6):t");testOstream(outfile,6);testOstream(outfile,"TestoftestOstream(outfile,true):t");testOstream(outfile,true);test
6、Ostream(outfile,"TestoftestOstream(outfile,8.6):t");testOstream(outfile,8.6);testOstream(outfile,"TestoftestOstream(outfile,"Good!"):t");testOstream(outfile,"Good!");outfile.close();cout<7、ss,8.6)/(oss,"Good!"):"<8、e时,传递用字符串字面值初始化的两个string对象。如果编写以下代码会发生什么?compare(“hi”,
7、ss,8.6)/(oss,"Good!"):"<8、e时,传递用字符串字面值初始化的两个string对象。如果编写以下代码会发生什么?compare(“hi”,
8、e时,传递用字符串字面值初始化的两个string对象。如果编写以下代码会发生什么?compare(“hi”,
此文档下载收益归作者所有