欢迎来到天天文库
浏览记录
ID:33726512
大小:1.18 MB
页数:234页
时间:2019-02-28
《More Exceptional C++ - 40 New Engineering Puzzles, Programming Problems, And Solutions (2001)(1st)(Herb Sutter)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、MoreExceptionalC++ByHerbSutterGenericProgrammingandtheC++StandardLibraryOneofC++'smostpowerfulfeaturesisitssupportforgenericprogramming.ThispowerisreflecteddirectlyintheflexibilityoftheC++standardlibrary,especiallyinitscontainers,iterators,andalgorithmsportion,originallyknownasthestanda
2、rdtemplatelibrary(STL).ThisopeningsectionfocusesonhowtomakethebestuseoftheC++standardlibrary,particularlytheSTL.Whenandhowcanyoumakebestuseofstd::vectorandstd::deque?Whatpitfallsmightyouencounterwhenusingstd::mapandstd::set,andhowcanyousafelyavoidthem?Whydoesn'tstd::remove()actuallyremo
3、veanything?Thissectionalsohighlightssomeusefultechniques,aswellaspitfalls,thatoccurwhenwritinggenericcodeofyourown,includingcodethat'smeanttoworkwithandextendtheSTL.WhatkindsofpredicatesaresafetousewiththeSTL;whatkindsaren't,andwhy?Whattechniquesareavailableforwritingpowerfulgenerictemp
4、latecodethatcanchangeitsownbehaviorbasedonthecapabilitiesofthetypesit'sgiventoworkwith?Howcanyouswitcheasilybetweendifferentkindsofinputandoutputstreams?Howdoestemplatespecializationandoverloadingwork?Andwhat'swiththisfunnytypenamekeyword,anyway?Thisandmore,aswedelveintotopicsrelatedtog
5、enericprogrammingandtheC++standardlibrary.Item1.SwitchingStreamsDifficulty:2What'sthebestwaytodynamicallyusedifferentstreamsourcesandtargets,includingthestandardconsolestreamsandfiles?1.Whatarethetypesofstd::cinandstd::cout?2.WriteanECHOprogramthatsimplyechoesitsinputandthatcanbeinvoked
6、equivalentlyinthetwofollowingways:ECHOoutfileECHOinfileoutfileInmostpopularcommand-lineenvironments,thefirstcommandassumesthattheprogramtakesinputfromcinandsendsoutputtocout.Thesecondcommandtellstheprogramtotakeitsinputfromthefilenamedinfileandtoproduceoutputinthefilenamedoutfil
7、e.Theprogramshouldbeabletosupportalloftheaboveinput/outputoptions.Solution1.Whatarethetypesofstd::cinandstd::cout?Theshortansweristhatcinboilsdownto:std::basic_istream>andcoutboilsdownto:std::basic_ostream>Thelongeranswers
此文档下载收益归作者所有