C++ 重置C+中的输出标志+;
我打算使用C++ 重置C+中的输出标志+;,c++,iostream,flags,iomanip,C++,Iostream,Flags,Iomanip,我打算使用resetiosglags函数将我结束的行上的所有输出标志重置为默认值。当我试图以这种方式进行操作时,它会提供错误的输出,这与我的预期相反 #include <iostream> #include <iomanip> using namespace std; int main() { bool first; int second; long third; float fourth; float fifth; dou
resetiosglags
函数将我结束的行上的所有输出标志重置为默认值。当我试图以这种方式进行操作时,它会提供错误的输出,这与我的预期相反
#include <iostream>
#include <iomanip>
using namespace std;
int
main()
{
bool first;
int second;
long third;
float fourth;
float fifth;
double sixth;
cout << "Enter bool, int, long, float, float, and double values: ";
cin >> first >> second >> third >> fourth >> fifth >> sixth;
cout << endl;
// ***** Solution starts here ****
cout << first << " " << boolalpha << first << endl << resetiosflags;
cout << second << " " << showbase << hex << second << " " << oct << second << endl << resetiosflags;
cout << third << endl;
cout << showpos << setprecision(4) << showpoint << right << fourth << endl << resetiosflags;
cout << scientific << fourth << endl << resetiosflags;
cout << setprecision(7) << left << fifth << endl << resetiosflags;
cout << fixed << setprecision(3) << fifth << endl << resetiosflags;
cout << third << endl;
cout << fixed << setprecision(2) << fourth << endl << resetiosflags;
cout << fixed << setprecision(0) << sixth << endl << resetiosflags;
cout << fixed << setprecision(8) << fourth << endl << resetiosflags;
cout << setprecision(6) << sixth << endl << resetiosflags;
// ***** Solution ends here ****
cin.get();
return 0;
}
#包括
#包括
使用名称空间std;
int
main()
{
布尔优先;
int秒;
长第三;
浮动第四;
浮动第五;
双六;
cout>第一>>第二>>第三>>第四>>第五>>第六;
库特
std::resetiosglags()
是一个用于表达式中的操纵器,例如outresetiosglags
是一个接受一个参数的函数。您不是在调用它,而是在打印它的地址。@IgorTandetnik鉴于我打算重置在每个语句末尾打开的标志,我应该考虑什么方法?
/*unspecified*/ resetiosflags( std::ios_base::fmtflags mask );
std::cout << ... << std::resetiosflags(std::ios_base::boolalpha);
std::cout << ... << std::noboolalpha;