C++ istringstream操作员>&燃气轮机;返回值
不幸的是没有帮助 我有一个在实现时抛出异常的软件,但我需要知道如何避免它。具体部分如下:C++ istringstream操作员>&燃气轮机;返回值,c++,tcp,istream,istringstream,C++,Tcp,Istream,Istringstream,不幸的是没有帮助 我有一个在实现时抛出异常的软件,但我需要知道如何避免它。具体部分如下: if (!(iss >> c)) { throw std::runtime_error( "No return code: status line doesn't begin with return code"); } 这就是整个方法 void parseReply(std::ostream& os, std::istream& is, std::str
if (!(iss >> c)) {
throw std::runtime_error(
"No return code: status line doesn't begin with return code");
}
这就是整个方法
void parseReply(std::ostream& os, std::istream& is, std::string &strReturn) {
std::string s;
int c;
while (std::getline(is, s)) {
strReturn += s;
strReturn += '\n';
std::istringstream iss(s);
if (!(iss >> c)) {
throw std::runtime_error(
"No return code: status line doesn't begin with return code");
}
if (CODE_OK == c
|| CODE_ERROR == c
|| CODE_BUSSY == c
|| CODE_UNKNOWN_CMD == c
) {
break;
}
}
if (CODE_OK != c
&& CODE_UNKNOWN_CMD != c
&& CODE_BUSSY != c
) {
throw std::runtime_error("error: " + s);
}
while (is >> s) {
flyelite::util::chop(s);
strReturn += s;
if (">" == s) {
return;
}
}
return;
该方法解析tcp消息应答的数据内容。每条消息都会用“>”字符进行确认
现在的问题是,iss
的内容有时(主要是当大量消息在循环中时)是:
“>250行”
正确的格式是
“好的”
- 当
的第一个内容是“>”时,为什么iss
返回(iss>>c)
false
- 发件人是否可能在其回答中返回了第二个“>
iss>>c
返回一个false,因为它需要一个整数,并且希望将值赋给变量c
,当它找不到这样的整数时,istream
进入错误状态
发件人是否可能在其回答中返回了第二个“>
很可能只是您在“状态”中看到的无法读入(由于上述原因)的输入流的剩余值
当iss的第一个内容是“>”时,(iss>>c)为什么返回false
当读入的字符是“>”时,iss>>c
返回一个false,因为它需要一个整数,并且希望将值赋给变量c
,当它找不到这样的整数时,istream
进入错误状态
发件人是否可能在其回答中返回了第二个“>
很可能是您在“状态”中看到的输入流中的剩余值无法读入(由于上述原因)Thank@Quiry,因此运算符>>对“目标”类型敏感。。。谢谢@好奇,所以操作员>>对“目标”类型很敏感。。。美好的