Advertisement Jump to content
Sign in to follow this  
Evan Gordon

xml file reading trouble

This topic is 1191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm working on implementing saving and reading for my current game I'm using PugiXML for reading and writing. 


It's gone rather smoothly 'till recently, i needed a vector of XML documents, so i could store the information for the last few game map files that have been used. But pugiXML didnt like me stuffing documents into a vector dynamically, so i messed with things a bit and now its a vector of unique_ptr 's which i figured should work, but now even though everything compiles and no exceptions are thrown during runtime it seems like when i use push_back() it seems like the document is being deleted as soon as its being created and i have no clue as to why. ill post the code I've got below, any help is as always appreciated biggrin.png

#include "pugixml.hpp"
#include <vector>
#include <memory>

std::vector<std::unique_ptr<pugi::xml_document>> mapFile;
std::string mapFileName = "test.xml";
mapFile.push_back(std::unique_ptr<pugi::xml_document>(new pugi::xml_document()));//even after this call size is remaining 0
pugi::xml_parse_result result = mapFile[mapFile.size() - 1]->load_file(mapFileName.c_str());
	std::cout<< "Load result: "<< result.description()<< ", mesh name: "<< mapFile[mapFile.size() - 1]->child("mesh").attribute("name").value()<< "\n";
	catch(std::exception e)
	        std::cout<<"Error: Failed to find "<< mapName << " the file was either moved or damaged.\n";
Edited by madgod_zhar

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!