jeudi 6 août 2020

How to use resetiosflags to reset ostream flags?

I tried using this, but encountered a compilation error. Unfortunately, I'm new to the compiler and don't understand the message. I'm trying to get the default &ostream flags back. Does anyone know how to properly reset the flags and what the error is reporting?

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

int main()
{
    int v = 0xFF;
    cout << "0x" << hex << v << resetiosflags(hex) << v << endl;

    return 0;
}

Compilation:

clang++ -Wall -std=c++11 -pedantic test251.cc && ./a.out
test251.cc:8:33: error: no matching function for call to 'resetiosflags'
    cout << "0x" << hex << v << resetiosflags(hex) << v << endl;
                                ^~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/iomanip:66:3: note: 
      candidate function not viable: no known conversion from
      'std::ios_base &(std::ios_base &)' to 'ios_base::fmtflags' (aka
      'std::_Ios_Fmtflags') for 1st argument
  resetiosflags(ios_base::fmtflags __mask)
  ^
1 error generated.

Aucun commentaire:

Enregistrer un commentaire