我如何将 char 传递给 find_child_by_attribute for pugixml

How do i pass a char into find_child_by_attribute for pugixml

我正在尝试将文件中的值传递到 tileNode.find_child_by_attribute("tileset","firstgid",container[0]).attribute("source").as_string()。它应该 return 图像路径的字符串。

#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], '[=10=]' };
cout << tileNode.find_child_by_attribute("tileset","firstgid",attr_value).attribute("source").as_string();

第一行将 container[0] 中的字符转换为 find_child_by_attribute 需要的空终止字符串。