C++/Console/cout sync clear

Материал из C\C++ эксперт
Перейти к: навигация, поиск

cout: Clears the buffer and resets any error flags that may be set

#include <iostream>    
#include <iomanip>     
#include <string>
using namespace std;
int main()
{
   string label;
   double price;
   cout << "Please enter an label: ";
   
   cin >> setw(16);        // cin.width(16);
   cin >> label;
   cin.sync();
   cin.clear();
   cout << "\nEnter the price: ";
   cin >> price;           
   
   cout << fixed << setprecision(2)   // Controlling output:
        << endl  << "Article:"
        << endl  << "Label:  " << label
        << endl  << "Price:  " << price << endl;
   return 0;
}


cout unset: clear flag

#include <iostream>
using namespace std;
int main()
{
  cout << 100 << " ";
  cout.unsetf(ios::dec); // clear dec flag
  cout.setf(ios::hex);
  cout << 100 << " ";
  cout.unsetf(ios::hex); // clear hex flag
  cout.setf(ios::oct);
  cout << 100 << "\n";
  return 0;
}