D25. 学习基础C、C++语言

D25. 输入输出

在C语言里,如果要输入是scanf("%d",&a),输出是printf("%d",a)
而在C++里面则是cin cout 来表示

#include <iostream>using namespace std;int main() {int a;cin>>a;a=a+3;    cout << a << endl;    return 0;}

其中endl的意思是end-of-line,也就是换行\n,要特别注意的是<< >>的方向,<< 是 output operator, 把右边的资料,传送给其左边的cout

试一下换行的用法

#include <iostream>using namespace std;int main() {int a=3;    cout << a << " ";    cout << a+3 << " ";    cout <<"next line" <<endl;cout << a+5<<endl;        return 0;}

输出内容
http://img2.58codes.com/2024/201436275hHu0K0LfL.jpg
(而在cout 到endl 之间的空格除非有用双引号隔出的才会显示)


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章