Note that there are some explanatory texts on larger screens.

plurals
  1. POSegmentation Fault when using RapidXML
    text
    copied!<p>When I run this it prints XML loaded and Dimensions loaded and then prints Segmentation Fault (core dumped). I copied an example I saw in the manual for RapidXML and a similar example was given on StackOverflow. Whats wrong with my implementation?</p> <p>data.xml</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;dimensions&gt; &lt;x&gt;400&lt;/x&gt; &lt;y&gt;400&lt;/y&gt; &lt;z&gt;1&lt;/z&gt; &lt;/dimensions&gt; </code></pre> <p>map.h</p> <pre><code>#ifndef MAP_H_ #define MAP_H_ class map{ public: std::vector&lt;int&gt; get_xml(); }; #endif </code></pre> <p>map.cpp</p> <pre><code>#include &lt;vector&gt; #include &lt;iostream&gt; #include "../lib/rapidxml.hpp" #include "../lib/rapidxml_print.hpp" #include "../lib/rapidxml_utils.hpp" using std::vector; using std::cout; using std::endl; using namespace rapidxml; vector&lt;int&gt; map::get_xml(){ file&lt;&gt; xmlFile("res/data.xml"); cout&lt;&lt;"XML loaded"&lt;&lt;endl; xml_document&lt;&gt; doc; xml_node&lt;&gt; *dims=doc.first_node("dimensions"); vector&lt;int&gt; values; cout&lt;&lt;"Dimensions loaded"&lt;&lt;endl; for(xml_node&lt;&gt; *dim=dims-&gt;first_node();dim;dim-&gt;next_sibling()){//breaks here cout&lt;&lt;"Looping through attributes"&lt;&lt;endl; values.push_back(atoi(dim-&gt;value())); } cout&lt;&lt;"All values loaded"&lt;&lt;endl; return values; } </code></pre> <p>main.cpp</p> <pre><code>#include &lt;vector&gt; #include "map.h" map Map; int main(int argc, char** argv){ std::vector&lt;int&gt; dims=Map.get_xml(); ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload