Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

C_Kurs_Lekt / DOC_RAZNOE / CPP_точность_cout

.pdf
Скачиваний:
11
Добавлен:
13.02.2016
Размер:
42.93 Кб
Скачать

#include <iostream> #include <iomanip> using namespace std;

/* #########################################################

1) что манипулятор setprecision(n) устанавливает точность вывода чисел типа float или double, он устанавливает количество выводимых цифр всего.

2) Использование манипулятора fixed ...

приводит к тому что точностью считается количество цифр после десятичной точки

3) как вариант setw(i) и . width(i)

######################################################### */ int main()

{ int i;

float s = 3.141592; double ds = 3.141592;

cout << "Hello world!" << endl;

cout<<setprecision(3)<< s << endl;

<< endl;

cout<<setprecision(3)<< ds << endl

cout<<setprecision(4)<< s << endl;

<< endl;

cout<<setprecision(4)<< ds << endl

cout<<setprecision(5)<< s << endl;

<< endl;

cout<<setprecision(5)<< ds << endl

cout << fixed << setprecision(3)<<

s << endl;

cout<< fixed <<setprecision(3)<< ds << endl << endl;

cout<< fixed <<setprecision(4)<< s

<< endl;

cout<< fixed <<setprecision(4)<< ds << endl << endl;

cout<< fixed <<setprecision(5)<< s

<< endl;

cout<< fixed <<setprecision(5)<< ds << endl << endl;

cout<<setprecision(3);

 

for (i = 3; i < 8; i++) {

 

}

cout << setw(i) << s << " " <<

s << endl;

for (i = 3; i < 8; i++) { cout.width (i);

}

} cout << 1001 << endl; return 0;

Hello world!

 

3.14

 

 

 

3.14

 

 

 

3.142

 

 

 

3.142

 

 

 

3.1416

 

 

3.1416

 

 

3.142

 

 

 

3.142

 

 

 

3.1416

 

 

3.1416

 

 

3.14159

 

 

3.14159

 

 

3.142

3.142

 

3.142

3.142

 

3.142

3.142

 

3.142

3.142

 

3.142 3.142

 

1001

 

 

 

1001

 

 

 

1001

 

 

 

1001

 

 

1001

 

 

Process returned 0 (0x0)

execution time : 0.109 s

Press any key to continue.