の アウトオブジェクト C++ では、 はクラス i ostream のオブジェクトです。で定義されています iostream ヘッダー ファイル 。標準出力デバイス、つまりモニターに出力を表示するために使用されます。これは、標準 C 出力ストリーム stdout に関連付けられています。画面に表示する必要があるデータは、挿入演算子(<<) を使用して標準出力ストリーム (cout) に挿入されます。
Javaカウンター
プログラム 1:
以下は、cout オブジェクトを実装するための C++ プログラムです。
C++
// C++ program to illustrate the use> // of cout object> #include> using> namespace> std;> // Driver Code> int> main()> {> >// Print standard output> >// on the screen> >cout <<>'Welcome to GFG'>;> >return> 0;> }> |
>
>出力:
Welcome to GFG>
注記: cout で挿入演算子 (<<) を使用すると、複数の変数を出力できます。
プログラム 2:
以下は、上記のアプローチを実装するための C++ プログラムです。
C++
// C++ program to illustrate printing> // of more than one statement in a> // single cout statement> #include> using> namespace> std;> // Driver Code> int> main()> {> >string name =>'Akshay'>;> >int> age = 18;> >// Print multiple variable on> >// screen using cout> >cout <<>'Name : '> << name << endl> ><<>'Age : '> << age << endl;> >return> 0;> }> |
>
>出力:
Name : Akshay Age : 18>
の coutステートメント 一部のメンバー関数でも使用できます。
- cout.write(char *str, int n): 最初の文字列を出力します。 N str から読み取る文字。 cout.put(char &ch):character に格納されている文字を出力します。 チャンネル 。 cout.precision(int n): 小数精度を次のように設定します。 N 、浮動小数点値を使用する場合。
プログラム 3:
以下は、のメンバー関数の実装です。 cout.write() そして cout.put() :
C++
np 平均
// C++ program to illustrate the use> // of cout.write() and cout.put()> #include> using> namespace> std;> // Driver Code> int> main()> {> >char> gfg[] =>'Welcome at GFG'>;> >char> ch =>'e'>;> >// Print first 6 characters> >cout.write(gfg, 6);> >// Print the character ch> >cout.put(ch);> >return> 0;> }> |
>
>出力:
Welcome>
プログラム 4:
以下は、の使用法を示す C++ プログラムです。 cout.precision() :
C++
// C++ program toillustrate the use> // of cout.precision()> #include> using> namespace> std;> // Driver Code> int> main()> {> >double> pi = 3.14159783;> >// Set precision to 5> >cout.precision(5);> >// Print pi> >cout << pi << endl;> >// Set precision to 7> >cout.precision(7);> >// Print pi> >cout << pi << endl;> >return> 0;> }> |
>
>出力:
3.1416 3.141598>