C++/Console/cout sync clear
cout: Clears the buffer and resets any error flags that may be set
<source lang="cpp">
- 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;
}
</source>
cout unset: clear flag
<source lang="cpp">
- 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;
}
</source>