資源描述:
《More Exceptional C++ - 40 New Engineering Puzzles, Programming Problems, And Solutions (2001)(1st)(Herb Sutter)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
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