#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
bool b1 = true;
cout << boolalpha << b1 << " " << noboolalpha << b1 << endl;
int i1 = 123;
cout << dec << i1 << " " << hex << i1 << " " << oct << i1 << endl;
cout << dec << showbase << i1 << " * " << dec << noshowbase << i1 << " # ";
cout << hex << showbase << i1 << " * " << hex << noshowbase << i1 << " # ";
cout << oct << showbase << i1 << " * " << oct << noshowbase << i1 << " #/n";
double d1, d2, d3;
d1 = 3.1415926534;
d2 = 2010.0;
d3 = 1.0e-10;
cout.precision(5);
cout << d1 << "/t" << d2 << "/t" << d3 << endl;
cout << fixed << d1 << "/t" << d2 << "/t" << d3 << endl;
cout << scientific << d1 << "/t" << d2 << "/t" << d3 << endl;
ofstream outfile1("test1.txt");
for (int n = 0; n < 100; ++n)
outfile1 << n << flush;
outfile1.close();
int i2 = -77;
cout.width(6); cout << dec << internal << i2 << endl;
cout.width(6); cout << left << i2 << endl;
cout.width(6); cout << right << i2 << endl;
double d4, d5, d6;
d4 = 30.0;
d5 = 10000.0;
d6 = 3.1416;
cout.precision(5);
cout.unsetf(ios::scientific);
cout << noshowpoint << d4 << '/t' << d5 << '/t' << d6 << endl;
cout << showpoint << d4 << '/t' << d5 << '/t' << d6 << endl;
int i3, i4, i5;
i3 = 1;
i4 = 0;
i5 = -1;
cout << noshowpos << i3 << '/t' << i4 << '/t' << i5 << endl;
cout << showpos << i3 << '/t' << i4 << '/t' << i5 << endl;
char ch1, ch2, ch3;
istringstream iss1(" 123");
iss1 >> noskipws >> ch1 >> ch2 >> ch3;
cout << ch1 << ch2 << ch3 << endl;
iss1.seekg(0);
iss1 >> skipws >> ch1 >> ch2 >> ch3;
cout << ch1 << ch2 << ch3 << endl;
ofstream outfile2("test2.txt");
outfile2 << nounitbuf << "Test " << "file" << endl;
cout << showbase << hex << nouppercase << 77 << endl << uppercase << 77 << endl;
cout << hex << setiosflags(ios::showbase) << 100 << endl;
cout << resetiosflags(ios::showbase) << 100 << endl;
cout << setbase(16) << 100 << endl << setbase(8) << 32 << endl;
cout << setbase(10) << resetiosflags(ios::showpos);
cout << setfill('x') << setw(10) << 77 << endl;
cout << hex << setiosflags(ios::showbase | ios::uppercase) << 100 << endl;
double d7 = 3.14159;
cout << setprecision(5) << d7 << endl;
cout << setprecision(9) << d7 << endl;
cout << fixed;
cout << setprecision(5) << d7 << endl;
cout << setprecision(9) << d7 << endl;
ofstream outfile3("test3.txt");
outfile3 << unitbuf << "Test " << "file" << endl;
outfile3.close();
char a[10], b[10];
istringstream iss2("one /n /t two");
iss2 >> noskipws >> a >> ws >> b;
cout << a << "," << b << endl;
return 0;
}
IOStream Manipulators
最新推荐文章于 2025-08-09 00:54:46 发布