【C++】关于c++的输入输出

这应该是我们写的第一个c++代码:

#include <iostream>

using namespace std;//展开c++标准库

int main()
{
	cout << "hello world" << std::endl;
    return 0;
}

其中,cout是输出,endl是换行,相当于c语言中的“\n”.

说明: 
1.使用cout标准输出(控制台)和cin标准输入(键盘)时,必须包含< iostream >头文件以及std标准命名空间。
注意:早期标准库将所有功能在全局域中实现,声明在.h后缀的头文件中,使用时只需包含对应头文件即可,后来将其实现在std命名空间下,为了和C头文件区分,也为了正确使用命名空间,规定C++头文件不带.h;旧编译器(vc 6.0)中还支持<iostream.h>格式,后续编译器已不支持,因此推荐使用<iostream>+std的方式。

c++输入输出好处:

使用C++输入输出更方便,不需增加数据格式控制,比如:整形-%d,字符--%c

#include <iostream>
using namespace std;

int main()
{

      int a;
      double b;char C;
      cin>>a;

      cin>>b>>c;
      cout<<a<< endl ; 
      cout<<b<<"  "<<c<<end1;

      return 0;
}



 

猜你喜欢

转载自blog.csdn.net/qq_42270373/article/details/83895889