Examly題庫立即開始練習
地方政府公務人員四等-資訊處理類科計算機概要10420單選題

下列程式執行後,執行結果為何? #include "stdafx.h" #include <iostream> #include <string> using namespace std; class SayHi { public: SayHi(string name) {setHiName(name);} void setHiName(string name) { hiName=name; } string getHiName() {return hiName;} void displayHiName() {cout << getHiName() << "!" << endl;} private: string hiName ; }; int _tmain(int argc , _TCHAR* argv[]) { SayHi hello1("Lunar"); SayHi hello2("Iris"); cout << "Say1: " << hello1.getHiName() << "\nSay2: "<< hello2.getHiName() << endl ; return 0 ; }

ASay1: Lunar Say2:Iris
BLunar Iris
CSay1: Lunar Say2: Iris正確答案
DLunar Iris
答案與詳解
C
正確答案
程式碼透過 `cout` 輸出字串,遇到 `\n` 會換行,因此輸出分為兩行且包含前綴字串。

為什麼答案是 C

正確輸出前綴字串、變數內容,並在遇到 `\n` 時正確換行。

載入中…

計算機概要 相關題目

想練更多計算機概要考古題?

Examly 收錄 38 萬+ 道歷屆題目,每題都有像這樣的精選詳解。免費下載,立即開練。

黑皮