Search code examples
c++boostxml-parsing

boost xml parsingl send a path of xml as variable


read_xml() function get a parameter of xml name and ptree member, but i want to send file's file directory such as C:\Users\serhan.erkovan\Desktop\ddd.xml as a variable. When i tried to do that it gives me error that cannot open file. How can i send file directory as a variable ?

My example code like this

ptree pt;
    try
    {
        read_xml("C:\\Users\serhan.erkovan\Desktop\ddd.xml", pt);
    }
    catch (const boost::property_tree::xml_parser::xml_parser_error &ex)
    {
        cerr << ex.what();
    }

Working example like this

ptree pt;
    try
    {
        read_xml("ddd.xml", pt);
    }
    catch (const boost::property_tree::xml_parser::xml_parser_error &ex)
    {
        cerr << ex.what();
    }

Solution

  • Working form is C:\\Users/serhan.erkovan/Desktop/ddd.xml as mentioned @Gupta and working example like this

    ptree pt;
        try
        {
            read_xml("C:\\Users/serhan.erkovan/Desktop/ddd.xml", pt);
        }
        catch (const boost::property_tree::xml_parser::xml_parser_error &ex)
        {
            cerr << ex.what();
        }