logo

cout C++:ssa

The cout esine C++:ssa on luokan i ostream objekti. Se on määritelty kohdassa iostream-otsikkotiedosto . Sitä käytetään tuotoksen näyttämiseen tavalliselle tulostuslaitteelle, eli näytölle. Se liittyy standardi C-lähtövirran stdout. Näytöllä näytettävät tiedot lisätään vakiolähtövirtaan (cout) käyttämällä insertio-operaattoria (<<) .

Ohjelma 1:



Alla on C++-ohjelma cout-objektin toteuttamiseksi:

C++






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

>

>

Lähtö:

Welcome to GFG>

Huomautus: Useampi kuin yksi muuttuja voidaan tulostaa käyttämällä lisäysoperaattoria (<<) ja cout.

Ohjelma 2:

Alla on C++-ohjelma yllä olevan lähestymistavan toteuttamiseksi:

C++




happoominaisuuksien tietokanta

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

>

>

Lähtö:

Name : Akshay Age : 18>

The cout lausunto voidaan käyttää myös joidenkin jäsentoimintojen kanssa:

    cout.write(char *str, int n): Tulosta ensimmäinen N hahmon lukeminen str. cout.put(char &ch): Tulosta merkkiin tallennettu merkki ch . cout.precision(int n): Asettaa desimaalitarkkuuden N , kun käytetään kelluvia arvoja.

Ohjelma 3:

Alla on jäsentoimintojen toteutus cout.write() ja cout.put() :

C++

k lähin naapuri




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

>

>

Lähtö:

Welcome>

Ohjelma 4:

kuinka päivittää javassa

Alla on C++-ohjelma havainnollistamaan käyttöä 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;> }>

>

>

Lähtö:

Greatandhra
3.1416 3.141598>