-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstd_ios.hpp
151 lines (107 loc) · 5.41 KB
/
std_ios.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef __STDIOS_H
#define __STDIOS_H
#include <iomanip>
#include <ios>
#include <limits>
using namespace std;
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
auto sum(auto x = 0.0, auto y = 0.0)
{
return x + y;
}
void std_ios()
{
auto x = 0.0;
auto y = 0.0;
auto res = 0.0;
string full_name;
int age;
std::cout << "Please, type num1, num2 to calculate:" << std::endl;
cout << "Num1: ";
std::cin >> x;
cout << "Num2: ";
cin >> y;
// res = x + y;
res = sum(x, y);
std::cout << "The result is: " << res << std::endl;
std::cout << "Please, Type your Full Name, and your age" << std::endl;
std::getline(cin, full_name);
std::cin >> age;
std::cout << "Welcome, " << full_name << "you are " << age << " years old." << std::endl;
int bin_to_int = 0b00001111;
int oct_to_int = 017;
int hex_to_int = 0x0f;
int dic_to_int = 15;
std::cout << bin_to_int << std::endl;
std::cout << oct_to_int << std::endl;
std::cout << hex_to_int << std::endl;
std::cout << dic_to_int << std::endl;
int x1(10);
int y1(10);
int z(x + y);
std::cout << z << std::endl;
std::cout << sizeof z << std::endl;
std::cout << sizeof(z) << std::endl;
char c = u8'f';
const char16_t *str {u"Ahmed Salama"};
std::cout << STR("HI, THERE") << std::endl;
}
void std_ioformat()
{
const unsigned WIDTH {50};
std::cout << std::boolalpha;
std::cout << true << std::endl;
std::cout << false << std::endl;
std::cout << "---------------" << std::endl;
std::cout << std::endl;
//std::cout << std::internal;
// std::cout << std::right;
std::cout << std::setfill('-');
std::cout << "Ahmed" << std::setw(WIDTH) << std::showpos << 37 << std::endl;
std::cout << std::right;
std::cout << "Mahmoud" << std::setw(WIDTH) << -79 << std::endl;
std::cout << "Elsayed" << std::setw(WIDTH) << std::noshowpos << 49 << std::endl;
std::cout << "Salama" << std::setw(WIDTH) << -150 << std::endl;
std::cout << "---------------" << std::endl;
std::cout << std::endl;
std::cout << "Message that will be flush...!" << std::endl << std::flush;
std::cout << "---------------" << std::endl << std::flush;
std::cout << std::endl << std::flush;
std::cout << std::uppercase;
std::cout << std::showbase;
std::cout << std::dec << "DECIMAL 10844: " << 10844 << std::endl;
std::cout << std::oct << "OCTAL 10844: " << 10844 << std::endl;
std::cout << std::hex << "HEX 10844: " << 10844 << std::endl; // using std::uppercase
std::cout << std::nouppercase << std::hex << "HEX 10844: " << 10844 << std::endl; // using std::nouppercase
std::cout << std::uppercase;
std::cout << std::noshowbase;
std::cout << std::dec << "DECIMAL 10844: " << 10844 << std::endl;
std::cout << std::oct << "OCTAL 10844: " << 10844 << std::endl;
std::cout << std::hex << "HEX 10844: " << 10844 << std::endl; // using std::uppercase
std::cout << std::nouppercase << std::hex << "HEX 10844: " << 10844 << std::endl; // using std::nouppercase
}
void std_numeric_limits()
{
const unsigned WIDTH (60);
std::cout << std::setfill('-');
std::cout << "Max int: " << setw(WIDTH) << std::numeric_limits<int>::max() << std::endl;
std::cout << "Max double: " << setw(WIDTH) << std::numeric_limits<double>::max() << std::endl;
std::cout << "Max float" << setw(WIDTH) << std::numeric_limits<float>::max() << std::endl;
std::cout << "Max long" << setw(WIDTH) << std::numeric_limits<long>::max() << std::endl;
std::cout << "Max long long" << setw(WIDTH) << std::numeric_limits<long long>::max() << std::endl;
std::cout << "Max Signed long long" << setw(WIDTH) << std::numeric_limits<signed long long>::max() << std::endl;
std::cout << "Min int: " << setw(WIDTH) << std::numeric_limits<int>::min() << std::endl;
std::cout << "Min double: " << setw(WIDTH) << std::numeric_limits<double>::min() << std::endl;
std::cout << "Min float" << setw(WIDTH) << std::numeric_limits<float>::min() << std::endl;
std::cout << "Min long" << setw(WIDTH) << std::numeric_limits<long>::min() << std::endl;
std::cout << "Min long long" << setw(WIDTH) << std::numeric_limits<long long>::min() << std::endl;
std::cout << "Min Signed long long" << setw(WIDTH) << std::numeric_limits<signed long long>::min() << std::endl;
std::cout << "Lowest int: " << setw(WIDTH) << std::numeric_limits<int>::lowest() << std::endl;
std::cout << "Lowest double: " << setw(WIDTH) << std::numeric_limits<double>::lowest() << std::endl;
std::cout << "Lowest float" << setw(WIDTH) << std::numeric_limits<float>::lowest() << std::endl;
std::cout << "Lowest long" << setw(WIDTH) << std::numeric_limits<long>::lowest() << std::endl;
std::cout << "Lowest long long" << setw(WIDTH) << std::numeric_limits<long long>::lowest() << std::endl;
std::cout << "Lowest Signed long long" << setw(WIDTH) << std::numeric_limits<signed long long>::lowest() << std::endl;
}
#endif