C++语言实现hello world代码

代码和注释

两种注释方式:

  • 一种是以/*开始、以*/结束的块注释(block comment);
  • 另一种是以//开始、以换行符结束的单行注释(line comment)。

 

以下用了几种方法来输出hello world


/* #include<iostream>
    #:预处理标志,后面跟预处理指令,include:预处理指令,包含 <iostream>:c++头文件,输入输出流
        这行的作用就是在预编译之前先执行这行代码。系统提供的头文件用<>括起来
   #include<iostream.h>
        这个头文件是c标准的头文件,c++中叫非标准库文件。
   using namespace std;使用标准命名空间。也就是说C++当中的标准库文件,函数,对象啊等都存放在std空间中,
        作用:作用是在编写大程序的时候能够定义重复的变量,(标识符)
        当需要调用标准空间中的对象,函数的时候调用方法:std::cout std::cin std::endl;需要加双冒号
    #include<iostream> #include<iostream.h>的区别:
        使用#include<iostream>的时候,需要使用using namespace std;而#include<iostream.h>不需要
*/
#include <iostream>
//using std::cout;  //使用std空间中cout对象。::调用的意思
//using std::endl;
int main(void)
{
    //cout<<"hello world"<<endl;
    std::cout<<"hello world"<<std::endl;
    return 0;
}
 
/*
#include<iostream>
using namespace std;
int main(void)
{
    cout<<"hello world"<<endl;
    return 0;
}
 
 
#include<iostream.h>
  int main(void)
  {
    cout<<"hello world"<<endl;
    return 0;
  }
*/

 

以下是C语言HelloWorld代码: 引用: ```c #include <iostream> using namespace std; int main() { cout << "HelloWorld" << endl; return 0; } ``` 引用: ```c #include <iostream> using namespace std; int main() { cout << "Hello world!" << endl; return 0; } ``` 引用: ```c cout << "Hello world!" << endl; ``` 这些代码实现了在控制台输出"Hello world!"的功能。其中,`cout`是C++中的输出流对象,`<<`是插入运算符,用于将字符串插入到输出流中,`endl`是控制符,表示换行。以上代码都是在C++环境下运行的,如果你需要在C环境下运行,可以将`#include <iostream>`和`using namespace std;`这两行代码删除。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [具体代码学习C++(01)--HelloWorld](https://blog.csdn.net/hanxiaochuan1/article/details/127409539)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [c++HelloWorld编写及解释:#include iostream、using namespace std](https://blog.csdn.net/mantou_riji/article/details/123387706)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值