阅读耗时 30 秒

Hello World

我们的第一个程序也是以Hello World 开始,输出 hello world is so easy

  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int main(){
  5. cout << "Hello World!" << endl;
  6. return 0;
  7. }

运行结果显而易见。 run一下,建议配置visual studio code 来跑 c++

$ g++ hello_world.cpp  //生成可执行文件
$ ./a.out

其中 需要引入 标准输入输出库 iostream, 利用cout 输出, endl 表示结束并换行,不加endl 加会不断在同一行追加显示,例如

#include<iostream>
#include<string>
using namespace std;

int main(){
    cout << "Hello World!";
    cout << "Hello World!";
    return 0;
}

输出结果

Hello World!Hello World!

注释

这个和其他语言类似
单行注释 //
多行注释 /** **/