我正在使用Qt开发一个C++应用程序,并使用调试器检查代码,我试图理解调试器报告的一些非常奇怪的结果。
if ( intDelimiter == -1
&& (intOpB = strProcessed.indexOf("[")) >= 0
&& (intClB = strProcessed.indexOf("]", ++intOpB) >= 0) ) {
strRef = strProcessed.mid(intOpB, intClB - intOpB);
if ( pobjNode != NULL ) {
strProcessed.replace(strRef, pobjNode->strGetAttr(strRef));
}我在线路上有个断点:
strRef = strProcessed.mid(intOpB, intClB - intOpB);在上面的代码片段中,strProcessed包含:
"1079-[height]"当命中断点时,intClB包含1,intOpB包含6。
intOpB是正确的,因为从indexOf返回的值是5,然后它在搜索"]“之前递增,但是intClB是不正确的,为什么调试器报告它为1?这对我来说毫无意义。
我正在使用:
Qt Creator 3.6.0
Based on Qt 5.5.1 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64bit)
Built On Dec 15 2015 01:01:12
Revision: b52c2f91f5正如king_nak所发现的,更正后的代码应该是:
if ( intDelimiter == -1
&& ((intOpB = strProcessed.indexOf("[")) >= 0
&& (intClB = strProcessed.indexOf("]", ++intOpB)) >= 0) ) {
strRef = strProcessed.mid(intOpB, intClB - intOpB);
if ( pobjNode != NULL ) {
strProcessed.replace(strRef, pobjNode->strGetAttr(strRef));
}
}发布于 2016-04-07 13:10:25
你把支撑放错了地方:
(intClB = strProcessed.indexOf("]", ++intOpB) >= 0)这将strProcessed.indexOf("]", ++intOpB) >= 0的结果分配给intClB,解释为int。因为这个语句是true,intClB = 1。
你想:
(intClB = strProcessed.indexOf("]", ++intOpB) ) >= 0
^ Brace herehttps://stackoverflow.com/questions/36476777
复制相似问题