gpt4 book ai didi

C++ 段错误 -tinyXML

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:00 24 4
gpt4 key购买 nike

当我尝试执行代码时遇到段错误,它编译时没有错误/警告,但在执行时给出错误段错误。下面是代码片段。

XMLElement *pStartTimeStamp = pRoot->FirstChildElement("mobileDevice")->FirstChildElement("RealTimeInformation");
XMLElement *pRealtimeStore = nullptr;
XMLElement *pIter0 = pStartTimeStamp->FirstChildElement("RunID");
while (pIter0 != nullptr) {
pRealtimeStore = pIter0;
pIter0 = pIter0->NextSiblingElement("startTimeStamp");
}

if (pRealtimeStore != nullptr) {
XMLElement *pNewStartTimeStamp = doc.NewElement("startTimeStamp");
pNewStartTimeStamp->SetText("pNewTimeStamp");
pStartTimeStamp->InsertAfterChild(pRealtimeStore, pNewStartTimeStamp);

}

编辑:我尝试运行 gdb 但结果是

Program received signal SIGSEGV, Segmentation fault.
0x0000000000402ada in tinyxml2::XMLNode::FirstChildElement (this=0x0, value=0x408dd8 "RunID") at tinyxml2.cpp:745
745 for( XMLNode* node=_firstChild; node; node=node->_next ) {

当单步执行代码时,它在这一行失败:

20      XMLElement *pIter0 = pStartTimeStamp->FirstChildElement("runID");
(gdb) next

Program received signal SIGSEGV, Segmentation fault.
0x0000000000402ada in tinyxml2::XMLNode::FirstChildElement (this=0x0, value=0x408dd8 "runID") at tinyxml2.cpp:745
745 for( XMLNode* node=_firstChild; node; node=node->_next ) {

XML 片段

<mobileDevice>
<mDeviceID></mDeviceID>
<deviceDescription></deviceDescription>
<units></units>
<devicePlacement></devicePlacement>
<quantisationResolution></quantisationResolution>
<realTimeInformation>
<runID/>
<sampleRate/>
<startTimeStamp/>
<endTimeStamp/>
<data/>
</realTimeInformation>
<event>
<mEventID/>
<timeStamp/>
<data/>
<support/>
</event>
</mobileDevice>

最佳答案

以下行似乎返回 null

XMLElement *pStartTimeStamp = pRoot->FirstChildElement("mobileDevice")->FirstChildElement("RealTimeInformation");

gdb 输出表明“this”指针为空,这一点很明显。

关于C++ 段错误 -tinyXML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26382384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com