C ++ setprecision

时间:2016-06-14 20:41:19

标签: c++

新手学习C ++而不理解我试图使用setprecision(2)的问题说setprecision(2)是未定义的。如果有人可以提供帮助,我将非常感激。

 #include <iostream>     
 #include <string>
using namespace std;

int main() 
{
double price,shipping;

cout<<"Enter total price of of the order: "<<endl;
cin>>price;

if(price > 75) 
    shipping = 0;
else if(price > 50) 
    shipping = 5;
else if(price > 25)
    shipping = 10;
else if(price > 0)
    shipping = 15;

cout<<"Total price of order including shipping is: "<<fixed<<setprecision(2)
    <<price + shipping<<endl;





return 0;
system("pause");
}

1 个答案:

答案 0 :(得分:3)

setprecision()函数包含在iomanip库中。只需将该库包含在您的程序中即可。你应该没事:)

#include<iomanip>