3GL   4GL   5GL   .

- ++

iostream

- iostream - stdio. iostream - , .

, iostream, , , .

iostream , "" , . - unsigned long, , .

stdio , . , printf() scanf(), .

iostream . - - , . -, iostream -.

iostream , stdio, , - .

iostream, , ++ . , ( ) .

, , - iostream. ( ++)

++
#include <stdio.h>
int i;
char buff[80];
printf (" :");
scanf("%d", &i);
printf (" :");
gets (buff);
printf (" : %d\n : %s\n", i, buff);
#include <iostream.h>
int i;
char buff[80];
cout << " :";
cin >> i >> buff;
cout << " :" << i << "\n" << " :" << buff << "\n";

( ), .

, , :

: 12
: My string

, printf(), , : %d, %s, printf() . , . - , , .

, iostream.

, . , printf(). , .

, . , , :

(((((cout<<"  :")<<i)<<"\n   :")<< buff)<<"\n");

cout iostream, .
cin
cerr .

,

cout<<"  :"

operator<<(), ostream, . operator << (ostream &, char*) iostream.h. ++ .

operator<<(cout, "  :")

operator << (ostream &, char*) , () cout ( ). "  :" , , ,

cout << i

operator <<(ostream &, int). , iostream . , operatop << ().

,

operator (ostream &, char*) cout "  :" cout
operator (ostream &, int) cout i cout
operator (ostream &, char*) cout "\n   :" cout
operator (ostream &, char*) cout buff cout
operator (ostream &, char*) cout "\n" cout

, iostream , , - . , , , .

, ++ , , . .

, cin, iostream.

cin >> i >> buff;

, , .

? , , . , . , , "12 ".

" 12", "" . iostream, scanf(), . , iostream .

scanf() . . iostream , -. -, .

, >> << , , .

,

ostream& operator << (ostream& stream, _& obj)
{
stream << ... // obj
// stream,
return stream;
}

istream& operator << (istream& stream, _& obj)
{
stream >> ... // obj
// stream,
return stream;
}

, , , . . , .

, . , , << ( >>), , .

cout << " "; out.operator << (" "); //

, , , cout.

, , ( ) . , , .

class _3d
{
  double x, y, z;
 public:
  _3d ();
  _3d (double initX, double initY, double initZ);
  double mod () {return sqrt (x*x + y*y +z*z);}
  double projection (_3d r) {return (x*r.x + y*r.y + z*r.z) / mod();}
  _3d& operator + (_3d& b);
  _3d& operator = (_3d& b);
  friend ostream& operator << (ostream& stream, _3d& obj);
  friend istream& operator >> (istream& stream, _3d& obj);
};

ostream& operator << (ostream& stream, _3d& obj)
{
 stream << "x=" << obj.x<< "y=" << obj.y << "z=" << obj.z;
 return stream;
}

istream& operator << (istream& stream, _3d& obj)
{
 stream >> obj.x >> obj.y >> obj.z;
 return stream;
}

main()
{
 _3d vecA;
 cin >> vecA;
 cout << "My vector: " << vecA << "\n";
}

( ) , ( ) .

iostream

, . iostream ios istream ostream. 25 , . .

int good () 1,
int eof () 1, " "
int fail () 1, - (, )
int bad () 1, -
int clear () -
int precision (int i)
int width (int i)

, .

#include <iostream.h>
int i;
char buff[80];
do{
 if (cin.fail()) cin.clear(); //
 cout << " :";
 cin >> i;
 if (cin.fail())
 {
  cout << " ";
  continue;
 }
 cin >> buff;
 if (cin.fail())
 {
  cout << " ";
  continue;
 }
} while (cin.fail()&&!cin.bad());
if (!cin.bad())
{
 cout << " :" << i << "\n"
 << " :" << buff << "\n";
}

. , , ( , ), , . , 80- . , cin , width() ios.

cin.width(sizeof(buff));
cin >> buff;

, -, -. - . , iomanip.h.

cin, width():

cin.width(sizeof(buff));
cin >> buff;

, setw(),

cin >> setw (sizeof (buff)) >> buff;

-: . iostream()

i/o
dec o 10-,
oct o 8-
hex o 16-
ws i
ends o
endl o
setfill (int ch) o -
setprecision(int n) o ( )
setbase (int b) o
setbase (int b) o
setiosflags (int f) i/o
resetiosflags (int f) i/o

left
right
dec, oct, hex -
showbase
showpoint
uppercase 16-
showpos "+"
scientific
fixed

, . , , . -, , . -, -.

. , , , , :

ios& manipul (ios&);

, ios ostream, istream.

, - , , .

:

ostream & right(ostream &)
{
 s << resetiosflags(ios::left) << setiosflags(ios::right);
 return s;
}

, . , right , , .

,
cout << setw(20) << right<< 1234 << endl;
. setw(20) 20 , right , , endl .

, ,    . , , iomanip.h.

iostream , : , . , , iostream,- .

- .

filebuf, ostream .

filebuf mybuff; //
// output
mybuff.open("output", ios::out);
ostream mycout(&mybuff); //
mycout <<12<<ends;
mybuff.close();

-. -,

ifstream ,
ofstream ,
fstream .

,

int i;
// , // input
ifstream mycout("input");
mycin >> i;

, fstream.h.

, strstrea.h.

, , .

char mybuff[128];
ostrstream mycout (mybuff, sizeof(mybuff));
mycout << 123 << ends;

mybuff "123".

,

int i;
char mybuff[128]= "123";
istrstream mycin (mybuff, sizeof(mybuff));
mycin >> i;

i 123.

, .

        3GL   4GL   5GL   .

, , Object - - :
- () ();
- , . , .




 10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _.
10.11.2021 - 12:36: - Conscience -> . ? - _.
10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _.
10.11.2021 - 12:35: - Ecology -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> . - _.
10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _.
10.11.2021 - 09:18: - New Technologies -> , 5G- - _.
10.11.2021 - 09:18: - Ecology -> - _.
10.11.2021 - 09:16: - Ecology -> - _.
10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _.
10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _.
Bourabai Research -  XXI Bourabai Research Institution