複数の 16 進文字列をコンソールに入力し、それらの文字列をビットセットに変換するようユーザーに要求する関数を作成しようとしています。ビットセットが親関数に格納されるように、関数でビットセットへのポインターを使用する必要があります。C++ 11 を使用していないため、64 ビット ビットセットを 2 つの 16 進変換操作に分割しました。
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]
先に進む方法がわかりません。演算子はビットセットで使用するの=
に有効なものであるため、エラーがわかりません。
ありがとう。