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);