Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 重载运算符的设置精度<&书信电报;_C++ - Fatal编程技术网

C++ 重载运算符的设置精度<&书信电报;

C++ 重载运算符的设置精度<&书信电报;,c++,C++,我让接线员超负荷工作了 我重载了操作符,只需将其链接:

我让接线员超负荷工作了
我重载了操作符,只需将其链接:
<如果你真的是指
253
(这是
(int)p.code
的值)也应该消失,就不要输出它。哈哈,我解释得不好。“我刚才说的只是钱的问题。”路易泽杜尔多夫说。我更新了答案,给出了一些额外的理由,说明为什么
out.setprecision(2)
不起作用。
ostream& operator<< (ostream &out, const Product& p) {
    return out << '\t' << (int)p.code << "\tR$ " << p.price << '\t' << p.name;
}
cout << this->items[i] << endl;
ostream& operator<< (ostream &out, const Product& p) {
    return out << '\t' << (int)p.code << "\tR$ " 
               << std::fixed << std::setprecision(2) 
               << p.price << '\t' << p.name;
}
struct _Setprecision { int _M_n; };

// This is what's actually called (both functions below):
inline _Setprecision 
    setprecision(int __n) { return { __n }; }

template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>& 
operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f)
{ 
    // Note you can alternatively call std::ostream::precision() function
    __os.precision(__f._M_n);
    return __os; 
}