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
|
#include "../std_lib_facilities.h"
void outotoputto (double a, double b, int c);
void intotoputto (double a, double b, int c);
int main()
{
//ofstream ofs("prova.txt", ios_base::out);
cout<<"Please enter a float number:\n";
double n = 0;
cin>>n;
cout<<"Please another one:\n";
double m = 0;
cin>>m;
cout<<"Now enter an int:\n";
int p = 0;
cin>>p;
intotoputto (n, m, p);
outotoputto (n, m, p);
return 0;
}
void outotoputto (double a, double b, int c)
{
ofstream ofs("prova.txt", ios_base::out);
ofs << int(a) << '\t' << oct << int(a) << '\t' << hex << int(a) << '\n';
ios state(nullptr);
state.copyfmt(cout); //Save the state
ofs << dec << b << '\t' << fixed << b << '\t' << scientific << b << '\n';
cout.copyfmt(state); //Restore the state
ofs << "Let's try to adjust the structure\n";
ofs << int(a) << setw(14) << oct << int(a) << setw(14) << hex << int(a) << '\n';
ofs << dec << c << setw(20) << oct << c << setw(20) << hex << c << '\n';
}
void intotoputto (double a, double b, int c)
{
cout << int(a) << '\t' << oct << int(a) << '\t' << hex << int(a) << '\n';
ios state(nullptr);
state.copyfmt(cout); //Save the state
cout << dec << b << '\t' << fixed << b << '\t' << scientific << b << '\n';
cout.copyfmt(state); //Restore the state
cout << "Let's try to adjust the structure\n";
cout << int(a) << setw(14) << oct << int(a) << setw(14) << hex << int(a) << '\n';
cout << dec << c << setw(20) << oct << c << setw(20) << hex << c << '\n';
}
|