欲輸入的最多16個十六進制字符到屏幕上,然後一個字符串字符串轉換爲一個bitset < 64>轉換十六進制的64位位集C++
到目前爲止我已成功以下
string tempString;
unsigned int tempValue;
cout << "enter addr in hex : ";
cin >> tempString;
istringstream ost(tempString);
ost >> hex >> tempValue;
bitset<32> addr(tempValue);
cout << "addr = " << addr << endl;
它工作正常,但當我重複64位它失敗。玩它似乎只能失敗的前32位!
bitset<64> wdata = 0;
if (rdnwr[0] == 0)
{
cout << "enter wdata in hex : ";
cin >> tempString;
istringstream ost1(tempString);
ost1 >> hex >> tempValue;
wdata = tempValue;
cout << "wdata = " << wdata << endl;
}
這是關於istringstream的最大尺寸嗎?或者也許我分配wdata的方式不同?
謝謝。
只是爲了確保,當你在做這64位,你是否將bitset <32>更改爲bitset <64> – DanChianucci
有幾個問題: 您應該使用uint64_t作爲您的tempValue(只是爲了確保您具有合適的大小int)。 我假設你已經更新了addr以聲明bitset <64>而不是32. – dallasstar
是的,我正在更新值,謝謝我應該這樣做! – user2646276