dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: rapidxml

Threaded View

  1. #1
    Join Date
    Nov 2011
    Posts
    18

    rapidxml

    Hello,

    i am trying to load and read a xml file using radipxml. Here is the code:

    Interface.h:

    Code:
    #include "../DataIO/Input.h"
    
    class CInterface{
    
    public:
    		
    	void GetInput();
    
    protected:
    
    	// To define a pointer to other class
    	CInput *pInput;
    };
    Interface.cpp:

    Code:
    #include <cstdio>
    #include <cstring>
    #include "../DataIO/Input.h" // Where Class CInput for xml file is defined
    #include "Interface.h"
    
    //Function to obtain the input data from xml file.
    // Call the Input.cpp file and his functions
    void CInterface::GetInput(){
    
    	//To define a pointer to file
    	FILE *pFile;
    	
    	const char* filename;
    	filename = "C:/Development/Test/Input.hun";
    	pFile = fopen(filename, "rt");
    
        if (pFile == NULL){ 
            puts("Couldn't open file"); 
            exit(0); 
        } 
    
    	// Call the Input.cpp file and his functions through the pointer
    	pInput->load(pFile);
            pInput->getInfo();
    }
    Input.h:

    Code:
    class CInput {
    
    private:
    
    	xml_document<> doc;	// character type defaults to char
    	vector<char> buffer; 
    
    public:
    	
    	// Definition of the function to get the data from InputFile
    	void load(FILE *pFile);
    };
    Input.cpp:

    Code:
    #include "rapidxml_utils.hpp"
    #include "Input.h"
    
    using namespace std;
    using namespace rapidxml;
    
    /**
        Load the xml document
    	make a safe-to-modify copy of input_xml
    */
    void CInput::load(FILE *pFile){
    
    	ifstream file("Input.hun");
    	/* "Read file into vector<char>" */ 
        vector<char> buffer((istreambuf_iterator<char>(file)), istreambuf_iterator<char>()); 
    	buffer.push_back('\0'); 
    	doc.parse<0>(&buffer[0]);	// 0 means default parse flags
    
    }
    The program builds without errors. But when debugging an Exception thrown: read access violation in function load. How can I solve the access violation?
    Thanks
    Last edited by 2kaud; April 10th, 2019 at 03:41 AM. Reason: Cleaned up code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)