Heim  >  Fragen und Antworten  >  Hauptteil

xcode - c++中关于boolalpha用法问题

关于boolalpha,我知道它可以将布尔类型以true或者false输出。
例如 :

bool x = ture;
cout << boolalpha << x << endl;

那么会输出true;
然而在xcode输出时会联想到这个函数

boolalpha(<#std::ios_base &__str#>)

这个是什么意思呢?

高洛峰高洛峰2713 Tage vor506

Antworte allen(1)Ich werde antworten

  • 怪我咯

    怪我咯2017-04-17 15:18:27

    std::boolalpha本身是函数,去调用ios_base::setf

    stream重载operator<< (std::ios_base& (*func)(std::ios_base&)).

    如果不做成函数就需要这样写,因为setf返回的是fmtflags,不是stream

    cout.setf(ios_base::boolalpha);
    cout << x << endl;

    Antwort
    0
  • StornierenAntwort