ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 运行 <details> <summary>main.cpp</summary> ``` #include <iostream> using namespace std; int main() { cout << "Hello World"; // 输出 Hello World return 0; } ``` </details> <br/> 运行 ``` $ g++ hello.cpp $ ./a.out Hello World ``` ## 新旧版本 ### 旧版本 ``` #include <iostream.h> //“.h”不能少 int main(void) { // Some Code } ``` ### 新版本 ``` #include <iostream> using namespace std; // 命名空间是必须的 int main() { // Some Code } ``` ## 函数等声明 实现在 main前无需声明 在main 后在需要在main前进行声明 无需声明 <details> <summary>main.cpp</summary> ``` #include <iostream> void demo() { std::cout<< "asd"; } int main() { demo(); return 0; } ``` 需要声明 </details> <br/> <details> <summary>main.cpp</summary> ``` #include <iostream> // 声明 void demo(); int main() { demo(); return 0; } void demo() { std::cout<< "asd"; } ``` </details> <br/>