Compilation error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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; }

21st Nov 2019, 5:24 AM
RAVI KUMAR
RAVI KUMAR - avatar
2 Answers
+ 9
RAVI 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)
21st Nov 2019, 5:31 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
Dear Sir , Thank you Very much .It solved my doubt.
22nd Nov 2019, 5:22 AM
RAVI KUMAR
RAVI KUMAR - avatar