C++ の入力と出力

フアン 序文

提示:文本为C++入门文章:

この記事では、入力と出力の使用方法について詳しく説明します


提示:以下是本篇文

シリーズ記事ディレクトリ

第 1 章C++ スペースの名前付け


記事ディレクトリ

目次

フアン 序文

シリーズ記事ディレクトリ

記事ディレクトリ

1. C++ の入出力の使用方法

1.入力

2. 出力 

要約する



提示:以下是本篇文章正文内容,下面案例可供参考

1. C++ の入出力の使用方法

1.入力

コードは次のとおりです(例)。

#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;
}

 結果は次のとおりです。 

分析します:

cin (入力用)

>> (ストリーム用の抜粋)

cin>>任意;

2. 出力 

コードは次のとおりです(例)。

#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;
}

結果は次のとおりです。 

​ 

分析します:

cout (出力用)

<< (ストリーム用)

endl (改行)

cout<< には任意の <<endl を指定できます。


要約する

printf 関数と scanf 関数は C++ でも使用できます。

使用する場合は、どちらが使いやすいかを考慮します。

おすすめ

転載: blog.csdn.net/qq_45591898/article/details/128808406
おすすめ