3.14:編寫一段程式,用cin讀入一組整數並把它們存入乙個vector物件。
【解答】:
#include
#include
using
namespace
std;
int main()
for (auto mem : vint) // 使用範圍for迴圈語句遍歷vint中的每個元素
cout
<< mem << " ";
cout
<< endl;
return
0;}
3.15:改寫上題的程式,不過這次讀入的是字串。
【解答】:
#include
#include
#include
using
namespace
std;
int main()
for (auto mem : vstring) // 使用範圍for迴圈語句遍歷vstring中的每個元素
cout
<< mem << " ";
cout
<< endl;
return
0;}
c primer 4 5節練習答案
練習4.17 前置運算子 加一後,返回的是修改後加一的值 後置運算子 加一後,返回的是未修改之前值的副本 練習4.18 如果返回的是加一之後的值,解引用該值將產生錯誤的結果,不但無法輸出第乙個元素,而且更糟的是如果序列中沒有負值,程式可能試 引用乙個根本不存在的元素。練習4.19 a 根據優先順序是...
c primer 5 3 1節練習答案
練習5.5 1 intmain 2 6while cin scores 715 else 1620 21 22 system pause 23return0 24 練習5.6 1 intmain 2 6while cin scores 711 system pause 12return0 13 練習...
c primer 6 5 2節練習答案
練習6.43 a 放在標頭檔案,因為內聯函式和constexpr函式一般寫在標頭檔案中 b 函式的定義一般寫在原始檔,而宣告放在標頭檔案 練習6.44 1 inline bool isshorter const string s1,const string s2 2 練習6.45 內聯函式一般用於優...