2
我在「Practical C++ Programming」一書中測試了代碼。 但下面的例子不像書中說的那樣工作。 我錯過了什麼?請幫忙。std :: cout :: setf不起作用(setf爲十六進制)
#include <iostream>
int main() {
int number = 0x3FF;
std::cout << "Dec: " << number << '\n';
std::cout.setf(std::ios::hex);
std::cout << "Hex: " << number << '\n';
std::cout.setf(std::ios::dec);
}
預期的結果是
Dec: 1023
Hex: 3ff
但是,我得到了
Dec: 1023
Dec: 1023
值得注意的是,您可以簡單地執行'std :: cout << std :: ios :: hex'。 –