// C++ 的标准输入输出头文件 input output stream
#include <iostream>
using namespace std;
// 标准输出
int main1()
{
// cout 类似于 printf, 作用是往屏幕打印数据
// 区别:cout 是个变量 printf 是个函数
// << : 左移操作符 和 cout 结合后功能变了,可以理解为数据流向
// 数据从右边流向左边
// 右边是 字符串 左边是屏幕 ==> 字符串 --> 屏幕
// endl 是一个换行
// C中的转义字符在C++同样可以使用
// cout 支持链式操作,数据流遵循先来后到的原则
cout << "hello\nworld" << endl;
// cout 可以自动识别变基础量类型
int a = 10;
char c = 'A';
float f = 1.2f;
double d = 2.3;
char *str= "hello world";
cout << "a = " << a << endl;
cout << "c = " << c << endl;
cout << "f = " << f << endl;
cout << "d = " << d << endl;
cout << "str = " << str << endl;
printf ("a = %d, c = %c\n", a, c);
cout << "a = " << a << ", c = " << c << endl;
return 0;
}
// 标准输入: cin
int main()
{
int a;
char c;
float f;
double d;
char str[20];
cin >> a >> c >> f >> d >> str;
cout << "a = " << a << endl;
cout << "c = " << c << endl;
cout << "f = " << f << endl;
cout << "d = " << d << endl;
cout << "str = " << str << endl;
// cout << "请输入一个整数:";
// cin >> a; // scanf ("%d", &a);
//cout << a << endl;
// 注意:cin cout 必须放到一行的最左边
// "hello" >> cout; 错误
return 0;
}
c++标准输入输出
最新推荐文章于 2025-05-17 09:24:18 发布