我如何将char传递到pugixml的find_child_by_attribute

i'm trying to pass a value from a file into tileNode.find_child_by_attribute("tileset","firstgid",container[0]).attribute("source").as_string(). it should return a string for an image path.

#include <iostream>
#include <vector>
#include "SFML/Graphics.hpp"
#include "../hpp/pugixml.hpp"

int main()
{
    std::vector <char> container = {};
    pugi::xml_document document;
    pugi::xml_parse_result result = document.load_file("./room/default.tsx");
    pugi::xml_node tileNode = document.child("map").child("tiledata");
    std::string gridRawData = document.child("map").child("layer").child("data").text().as_string();
    int z = 0;
    int y = 0;
    //read map key from file
    for(int x = 0; x < gridRawData.size(); x++)
    {
        if(document.child("map").child("layer").child("data").child_value()[x] != '\n' &&
            document.child("map").child("layer").child("data").child_value()[x] != ',')
        {
           container.push_back(gridRawData[x]);
        };
    }




    std::cout<<tileNode.find_child_by_attribute("tileset","firstgid",container[0]).attribute("source").as_string();

    return 0;
};```

it gives error:
```it gives error
||=== Build: Release in projectrpg (compiler: GNU GCC Compiler) ===|
C:\Users\Nyanners\Desktop\gamedevhell\projectrpg\projectrpg\cpp\main.cpp||In function 'int main()':|
C:\Users\Nyanners\Desktop\gamedevhell\projectrpg\projectrpg\cpp\main.cpp|17|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
C:\Users\Nyanners\Desktop\gamedevhell\projectrpg\projectrpg\cpp\main.cpp|29|error: invalid conversion from '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}' to 'const char_t* {aka const char*}' [-fpermissive]|
C:\Users\Nyanners\Desktop\gamedevhell\projectrpg\projectrpg\hpp\pugixml.hpp|648|note:   initializing argument 3 of 'pugi::xml_node pugi::xml_node::find_child_by_attribute(const char_t*, const char_t*, const char_t*) const'|
C:\Users\Nyanners\Desktop\gamedevhell\projectrpg\projectrpg\cpp\main.cpp|14|warning: unused variable 'z' [-Wunused-variable]|
C:\Users\Nyanners\Desktop\gamedevhell\projectrpg\projectrpg\cpp\main.cpp|15|warning: unused variable 'y' [-Wunused-variable]|
||=== Build failed: 1 error(s), 3 warning(s) (0 minute(s), 2 second(s)) ===|```


评论
  • 呐爱
    呐爱 回复

    因此,对您的实际意思进行一个疯狂的猜测,我会为此感到吃饱

    char attr_value[] = { container[0], '\0' };
    cout << tileNode.find_child_by_attribute("tileset","firstgid",attr_value).attribute("source").as_string();
    

    The first line converts the character in container[0] into the null terminated string that find_child_by_attribute requires.