logo

C++의 cout

그만큼 cout 객체 C++에서는 클래스 i ostream의 객체입니다. 이는 다음에서 정의됩니다. iostream 헤더 파일 . 표준 출력 장치, 즉 모니터에 출력을 표시하는 데 사용됩니다. 이는 표준 C 출력 스트림 stdout과 연결됩니다. 화면에 표시해야 하는 데이터는 삽입 연산자(<<)를 사용하여 표준 출력 스트림(cout)에 삽입됩니다.

프로그램 1:



다음은 cout 객체를 구현하는 C++ 프로그램입니다.

C++

xvideoservicethief 우분투 14.04 다운로드








// 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:

자바 tostring 메소드

다음은 위의 접근 방식을 구현하는 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.write(char *str, int n): 첫 번째를 인쇄합니다. N str에서 문자를 읽습니다. cout.put(char &ch): 문자에 저장된 문자를 인쇄합니다. 채널 . cout.precision(int n): 소수점 정밀도를 다음으로 설정합니다. N , 부동 소수점 값을 사용할 때.

프로그램 3:

자바 참조 유형

아래는 멤버 함수의 구현입니다. cout.write() 그리고 cout.put() :

C++




// 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.정밀() :

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>