[問題] 關於名稱空間

看板C_and_CPP (C/C++)作者 (*〞︶〝*)時間11年前 (2015/04/29 22:19), 11年前編輯推噓1(105)
留言6則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 面試時遇到的考題, 只大概打出題意 答案有三個, 想不出最後一個 餵入的資料(Input):預期的正確結果(Expected Output): 我填的答案有兩個 1. 第2行加入 using namespace std; 2. 第5行改成 std::cout << "hello world!" << std::endl; 錯誤結果(Wrong Output):程式碼(Code):(請善用置底文網頁, 記得排版) 1 #include <iostream> 2 3 int main() 4 { 5 cout << "hello world!" << endl; 6 return 0; 7 } 補充說明(Supplement):無 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.165.200.161 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1430317168.A.1ED.html ※ 編輯: zelkova (118.165.200.161), 04/29/2015 22:20:12

04/29 22:27, , 1F
using std::cout; using std::endl;
04/29 22:27, 1F

04/29 22:54, , 2F
4. #define cout std::cout
04/29 22:54, 2F

04/29 22:58, , 3F
5. auto &cout = std::cout;const char* endl = "\n";
04/29 22:58, 3F

04/30 00:12, , 4F
6. #define cout /##/ ~快逃~
04/30 00:12, 4F

04/30 09:03, , 5F
要這樣玩不是有無限個可能 寫個cout來override也可
04/30 09:03, 5F

04/30 19:39, , 6F
謝謝大大 這是某間蠻有名公司的考題之一 不過我也沒答案
04/30 19:39, 6F
文章代碼(AID): #1LGEXm7j (C_and_CPP)
文章代碼(AID): #1LGEXm7j (C_and_CPP)