本 Wiki 开启了 HTTPS。但由于同 IP 的 Blog 也开启了 HTTPS,因此本站必须要支持 SNI 的浏览器才能浏览。为了兼容一部分浏览器,本站保留了 HTTP 作为兼容。如果您的浏览器支持 SNI,请尽量通过 HTTPS 访问本站,谢谢!
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版 | |||
cs:programming:cpp:cpp_primer:answers:chpt_8 [2024/01/14 13:46] – 移除 - 外部编辑 (未知日期) 127.0.0.1 | cs:programming:cpp:cpp_primer:answers:chpt_8 [2024/01/14 13:46] (当前版本) – ↷ 页面programming:cpp:cpp_primer:answers:chpt_8被移动至cs:programming:cpp:cpp_primer:answers:chpt_8 codinghare | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ======Chapter.8====== | ||
+ | Answers for chapter 8 | ||
+ | ---- | ||
+ | ==ex.8.1== | ||
+ | > | ||
+ | <code cpp> | ||
+ | std:: | ||
+ | reader(std:: | ||
+ | std:: | ||
+ | while(is >> word) { | ||
+ | std:: | ||
+ | } | ||
+ | is.clear(); | ||
+ | return is; | ||
+ | } | ||
+ | </ | ||
+ | ==ex.8.2== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.3== | ||
+ | > | ||
+ | <code cpp> | ||
+ | while (cin >> i) /* ... */ | ||
+ | </ | ||
+ | Execpt for // | ||
+ | ==ex.8.4== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.5== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.6== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | [[https:// | ||
+ | ==ex.8.7== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.8== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.9== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.10== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.11== | ||
+ | >The program in this section defined its istringstream object inside the outer while loop. What changes would you need to make if record were defined outside that loop? Rewrite the program, moving the definition of record outside the while, and see whether you thought of all the changes that are needed. | ||
+ | The program will print either nothing or whatever string " | ||
+ | The istringstream object defined in a loop is a temporary object. It is created, destroyed and bound to the newest line from the input each loop. That allows us to bind an isstringstream object to every line of the outer loop, then print every element in the line. If we choose to move the object definition out of the outer loop, it will be bound to the default, empty string " | ||
+ | |||
+ | <code cpp> | ||
+ | /* test result */ | ||
+ | //input | ||
+ | aaa 111 | ||
+ | bbb 222 | ||
+ | ccc 333 | ||
+ | ddd 444 | ||
+ | //output, the string line has default value "Hello word." | ||
+ | Hello word. | ||
+ | </ | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.12== | ||
+ | > | ||
+ | The // | ||
+ | ==ex.8.13== | ||
+ | > | ||
+ | CODE: [[https:// | ||
+ | ==ex.8.14== | ||
+ | > | ||
+ | |||
+ | * Adding const: Modifications are no needed for entry and nums. | ||
+ | * Adding reference: Passing a string with a reference is more efficient. |