Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 没有接线员的对手_C++_Bitset - Fatal编程技术网

C++ 没有接线员的对手

C++ 没有接线员的对手,c++,bitset,C++,Bitset,我试图编写一个函数,要求用户向控制台输入多个十六进制字符串,然后将这些字符串转换为位集。我希望函数使用指向位集的指针,以便位集存储在父函数中。由于不使用C++ 11,我将64位的比特集分成两个十六进制转换操作。 void consoleDataInput(bitset<1> verbose, bitset<32>* addr, bitset<64>* wdata, bitset<8>* wdata_mask, bitset<1>* rd

我试图编写一个函数,要求用户向控制台输入多个十六进制字符串,然后将这些字符串转换为位集。我希望函数使用指向位集的指针,以便位集存储在父函数中。由于不使用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;
    }
据我所知,我不需要在
wdata[I+32]
之前使用*运算符,因为
[I+32]
表示它是指针

我不知道如何前进。
=
运算符是用于位集的有效运算符,因此我不理解错误


谢谢。

您的wdata确实是一个指针,因此wdata[i+32]实际上相当于*(wdata+i+32),指向一个位集。您正在使用tempBitset[i]分配此位集,除非我弄错了,否则tempBitset[i]是单个位

也就是说,您试图将单个位的值分配给整个位集

我怀疑您想要将一个位集中的一个位设置为另一个位中的一个位的值,在这种情况下,我想您确实需要“*”:

(*wdata)[i+32] = tempBitset[i];

这大致意味着,取wdata指向的位集,并将其位[i+32]设置为与tempBitset中位集的位[i]相同的值。

我将使用引用,而不是指针。
wdata[i+32] = tempBitset[i];
(*wdata)[i+32] = tempBitset[i];