Compilation error
Hello all, I am very new for C++ programming . As I was exercising the same , I got compilation error for this programme , can anyone guide me where I am wrong . Thank you in advance. # include <iostream> # include <iomanip> # include <string> using namespace std; int main() { string label; double price; cout <<"\nPlease enter an article label: "; cin >> setw; cin >> label; cin.sync(); cin.clear(); cout << "\nEnter the price of teh article: "; cin >> price; cout << fixed << setprecision(2) << "\nArticle:" << "\n Label: " << label <<"\n Price: " << price << endl; return 0; }
11/21/2019 5:24:20 AM
RAVI KUMAR
2 Answers
New AnswerRAVI KUMAR you have to use cin>>setw(50); # include <iostream> # include <iomanip> # include <string> using namespace std; int main() { string label; double price; cout <<"\nPlease enter an article label: "; cin >> setw(50); cin >> label; cin.sync(); cin.clear(); cout << "\nEnter the price of teh article: "; cin >> price; cout << fixed << setprecision(2) << "\nArticle:" << "\n Label: " << label <<"\n Price: " << price << endl; return 0; } This way it will execute correctly else setw() will give error The setw() method of iomaip library in C++ is used to set the ios library field width based on the width specified as the parameter to this method. Syntax: setw(int n)