我正在尝试编写一个函数,要求用户将多个十六进制字符串输入到控制台,然后将这些字符串转换为位集。我希望该函数使用指向位集的指针,以便将位集存储在父函数中。由于不使用 c++ 11,我将 64 位位集拆分为两个十六进制转换操作。
void consoleDataInput(bitset<1> verbose, bitset<32>* addr, bitset<64>* wdata, bitset<8>* wdata_mask, bitset<1>* rdnwr)
{
cout << "enter 1 for read 0 for write : ";
cin >> *rdnwr;
string tempStr;
unsigned long tempVal;
istringstream tempIss;
// Input the addr in hex and convert to a bitset
cout << "enter addr in hex : ";
cin >> tempStr;
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
*addr = tempVal;
// enter wdata and wdata_mask in hex and convert to bitsets
if (rdnwr[0] == 1)
{
*wdata = 0;
*wdata_mask = 0;
}
else
{
// wdata
bitset<32> tempBitset;
cout << "enter wdata in hex : ";
cin >> tempStr;
if (tempStr.length() > 8)
{
tempIss.str(tempStr.substr(0,tempStr.length()-8));
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=31; i>=0; i--)
{
wdata[i+32] = tempBitset[i];
}
tempIss.str(tempStr.substr(tempStr.length()-8,tempStr.length()));
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=32; i>=0; i--)
{
wdata[i] = tempBitset[i];
}
}
else
{
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=32; i>=0; i--)
{
wdata[i] = tempBitset[i];
}
}
// wdata_mask
cout << "enter wdata_mask in hex : ";
cin >> tempStr;
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
*wdata_mask = tempVal;
}
当我尝试在 code::blocks 中使用 GCC 进行编译时,出现错误
C:\Diolan\DLN\demo\ApolloSPI\main.cpp|202|error: no match for 'operator=' in '*(wdata + ((((sizetype)i) + 32u) * 8u)) = std::bitset<_Nb>::operator[](std::size_t) [with unsigned int _Nb = 32u; std::size_t = unsigned int](((std::size_t)i))'|
突出显示该行
wdata[i+32] = tempBitset[i];
据我了解,我之前不需要使用 * 运算符,wdata[i+32]
因为[i+32]
它表明它是一个指针。
我不确定如何前进。该=
运算符是与 bitset 一起使用的有效运算符,因此我不明白该错误。
谢谢。