第零章以 Hello World 為切入點,介紹註釋、#include、main 函數、輸入輸出語句、轉義字符等基礎概念。以下為部分習題的參考實現(均通過編譯驗證)。
#include <iostream>
int main() {
std::cout << "This (\") is a quote, and this (\\) is a backslash." << std::endl;
return 0;
}
#include <iostream>
int main() {
std::cout << "// a small C++ program\n"
"#include <iostream>\n"
"\n"
"int main()\n"
"{\n"
"\tstd::cout << \"Hello, world!\" << std::endl;\n"
"\treturn 0;\n"
"}" << std::endl;
return 0;
}
int main() {}
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
std::cout、std::endl、字符串字面量拼接規則\"、\\、\n、\t 是考試與面試常考點