HUAN Preface
提示:文本为C++入门文章:
This article explains in detail how to use input and output
提示:以下是本篇文
Series Article Directory
Chapter 1 C++ Space Naming
Article directory
Table of contents
1. How to use C++ input and output
提示:以下是本篇文章正文内容,下面案例可供参考
1. How to use C++ input and output
1. Input
The code is as follows (example):
#include <iostream>
using namespace std;
int main()
{
int x = 10;
double y = 11.11;
char z[20] = "hello world";
cin >> x >> y >> z;
cout << x << endl;
cout << y << endl;
cout << z << endl;
return 0;
}
The result is as follows:
analyze:
cin (for input)
>> (extract for stream)
cin>>any;
2. Output
The code is as follows (example):
#include <iostream>
using namespace std;
int main()
{
int x = 10;
double y = 11.11;
char z[] = "hello world";
cout << "你好" << endl;
cout << x << endl;
cout << y << endl;
cout << z << endl;
return 0;
}
The result is as follows:
analyze:
cout (for output)
<< (for stream)
endl (line feed)
cout<< can be any <<endl;
Summarize
The printf and scanf functions can also be used in C++
When we choose to use, we look at which one is convenient for us to use