如何将字符传递到find_child_by_attribute中以获取 pugixml



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

#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:UsersNyannersDesktopgamedevhellprojectrpgprojectrpgcppmain.cpp||In function 'int main()':|
C:UsersNyannersDesktopgamedevhellprojectrpgprojectrpgcppmain.cpp|17|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
C:UsersNyannersDesktopgamedevhellprojectrpgprojectrpgcppmain.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:UsersNyannersDesktopgamedevhellprojectrpgprojectrpghpppugixml.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:UsersNyannersDesktopgamedevhellprojectrpgprojectrpgcppmain.cpp|14|warning: unused variable 'z' [-Wunused-variable]|
C:UsersNyannersDesktopgamedevhellprojectrpgprojectrpgcppmain.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], '' };
cout << tileNode.find_child_by_attribute("tileset","firstgid",attr_value).attribute("source").as_string();

第一行将container[0]中的字符转换为find_child_by_attribute所需的以 null 结尾的字符串。

相关内容

  • 没有找到相关文章

最新更新