Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.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++ istringstream未更改c++;_C++_Istringstream - Fatal编程技术网

C++ istringstream未更改c++;

C++ istringstream未更改c++;,c++,istringstream,C++,Istringstream,我已经写了一些代码来说明我在另一个程序中转换一些输入字符串时遇到的问题 #include <iostream> #include <sstream> #include <bitset> using namespace std; int main() { string tempStr; unsigned long tempVal; istringstream tempIss; bitset<32>

我已经写了一些代码来说明我在另一个程序中转换一些输入字符串时遇到的问题

#include <iostream>
#include <sstream>
#include <bitset>

using namespace std;

int main()
{
    string        tempStr;
    unsigned long tempVal;
    istringstream tempIss;
    bitset<32>    tempBitset;

    // Input the first word in hex and convert to a bitset

    cout << "enter first word in hex : ";
    cin >> tempStr;
    tempIss.str(tempStr);
    cout << "word2 tempIss : " << tempIss.str() << endl;
    tempIss >> hex >> tempVal;
    cout << "word2 tempVal : " << (int)tempVal << endl;
    tempBitset = tempVal;
    cout << "word1 tempBitset: " << tempBitset.to_string() << endl;

    // Input the second word in hex and convert to a bitset

    cout << "enter second word in hex : ";
    cin >> tempStr;
    tempIss.str(tempStr);
    cout << "word2 tempIss : " << tempIss.str() << endl;
    tempIss >> hex >> tempVal;
    cout << "word2 tempVal : " << (int)tempVal << endl;
    tempBitset = tempVal;
    cout << "word2 tempBitset: " << tempBitset.to_string() << endl;

    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串tempStr;
无符号长tempVal;
地峡流;
位集tempset;
//以十六进制输入第一个字并转换为位集
cout>tempStr;
tempIss.str(tempStr);
cout>tempVal;
库特
这只是设置内部缓冲区的内容,但不会重置先前操作中可能在流上设置的错误标志

在第二次提取之前说
tempIss.clear();
应该完成这项工作。

if(!(tempIss>>hex>>tempVal))process_error();else output();
tempIss.str(tempStr);