/* * streams.cpp * * Created on: 03.10.2013 * Author: trifon */ #include #include #include using namespace std; int main1() { int a,b,c; istrstream is("1 2 3"); // лошо: // istream& cin = is; cout << "Peek! " << cin.peek() << endl; cout << "Now I will input a: "; cin >> a; cout << a << endl; cin >> b; cout << b << endl; cin >> c; cerr << c << endl; // !!!! int d[10] = { 65, 66, 67, 68, 69 }; // cout.write((char const*)d, 20); for(int i = 0; i < 5; i++) cout << d[i] << ' '; // cin.get((char&)d[0]); cin.read((char*)d, 2 * sizeof(int)); cout << endl << d[0] << endl << d[1] << endl; // !!! } ostream& my_strange_manipulator(ostream& os) { os << setfill('.') << hex; os.width(10); os.setf(ios::internal | ios::showbase); return os; } int main() { int x = -1; cout << "Моля, въведете x: "; cin >> x; if (cin) { cout << "Всичко е наред!\n"; } else { do { cout << "Не сте въвели число!\n"; cout << "Потокът е във състояние: " << cin.rdstate() << endl; char tmp[10]; int gc; do { cin.clear(); cin.get(tmp, 10); gc = cin.gcount(); cout << "Прочетени: " << gc << endl; } while (gc == 9); // (как да решим въпроса при точно 9 въведени символа? cout << "Моля, въведете отново: "; cin >> x; } while (!cin); } cout << "Good = " << cin.good() << endl; cout << "EOF = " << cin.eof() << endl; cout << "Fail = " << cin.fail() << endl; cout << "Bad = " << cin.bad() << endl; cout << "Въведохте " << x << endl; /* cout.precision(5); cout.width(10); cout.fill('x');*/ cout << setprecision(15) << setw(10) << setfill('x') << 1.2345678 << endl; cout << 100.0 << setiosflags(ios::fixed) << endl << 100.0; cout << resetiosflags(ios::fixed) << setiosflags(ios::scientific) << endl << 100.0 << endl; cout << setfill('.'); cout << hex << setiosflags(ios::internal | ios::showbase) << setw(10) << 100 << endl; cout << my_strange_manipulator << 100 << endl; return 0; }