, . , , .
iostream.h iomanip.h ( ).
.
#include<iomanip.h>
main()
{
int a = 157;
double b = 1.55555;
cout << setw(10) << a << endl;
/* setw (n) , .. n , . 8- , 7 : 157 ( ). . */
cout << setw(10) << setfill(z) << a << endl;
/* setwfill (kod) , ( 122 ' z '). : zzzzzzz157. setwfill (0).*/
cout << oct << a << endl;
/* oct 8- . : 235 */
cout << hex << a << endl;
// hex 16- . : 9d
cout << dec << a << endl;
// dec 10-. : 157
cout << b << endl; // : 1.55555
cout << setprecision(3) << b << endl;
/* setprecision (n) n , . :
1.56 1.556 */
return 0;
}
, ios, .
setiosflags (ios:: flag);
resetiosflags (ios:: flag);
, | ( ) .
.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main(void) {
int a = 157;
cout<<setiosflags(ios:: showbase)<<a<< <<oct<<a<<
<<hex<<a<< endl;
/* showbase , . : 157 0235 09d */
double a1 = 12.99, a2 = 15;
cout << setiosflags(ios:: showpoint | ios:: fixed)
/* showpoint , fixed */
<< setprecision(2) << setfill(*) << setiosflags(ios:: right)
// right ( left)
<< a1 << setw(10) << a1
|
|
<< a2 << setw(10) << a2 << endl;
// : a1 *****12.99 a2 *****15.00
double pi = 3.14159;
cout << Pi << setw(15) << setfill(_)
// _
<< setiosflags(ios:: showpos | ios:: scientific)
<< setprecision(5) << pi << endl;
/* showpos +, scientific . : Pi _ _ _ +3.14159e+00 */
}
, , .
16.3. - Visual C++
Visual C++ 6.0 ( ) . , , , - , . Visual C++ 6.0 :
#include <iostream.h>
int main()
{
cout << "Welcome to C++!" << endl;
cout << " C++!" << endl;
return 0;
}
:
Welcome to C++!
─ C++!
Press any key to continue
. MS DOS Windows.
- ASCII. , .. 0 127, 128 255 . , , (Alt), (Mai), (MIC), -8 (KOI), . ASCII.
, Visual C++, ANSI. ASCII, , Visual , MS DOS ASCII.
, , CharToOem, ANSI ASCII. , () ANSI, OemToChar. windows. h.
:
#include <iostream.h>
#include <windows.h>
char* Rus(const char* text);
char bufRus[255];
int main()
{
char s[] = "!", ss[100];
cout << Rus(" ") << Rus(s) <<endl;
cout << Rus(" :");
cin >> ss;
cout << Rus(" : ") << ss << endl;
|
|
return 0;
}
char* Rus (const char* text)
{
CharToOem(text, bufRus);
return bufRus;
}
:
!
: !
: !
, Visual C++ 6.0 Rus, CharToOem, . bufRus. : ( ) Rus ( ).
CharToOem, , , BOOL, . , : Rus << , .
new delete
++ new delete. :
1) type * p = new type (); sizeof (type), , ;
...
delete p; .
2) type * p = new type [ n ]; n , n * sizeof (type); ;
...
delete [] p; .
, delete , , .
delete [ ] , , . .