Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C++ 中。我将 bitset 初始化为 -3,例如:
std::bitset<32> mybit(-3);
有没有一种优雅的方式可以转换mybit为-3. 因为 bitset 对象只有 和 之类的to_ulong方法to_string。
mybit
-3
to_ulong
to_string
使用to_ulong将其转换为unsigned long,然后使用普通强制转换将其转换为int。
unsigned long
int
int mybit_int; mybit_int = (int)(mybit.to_ulong());
演示