pugi::char_t* 到 const char*

pugi::char_t* to const char*

SO上有一些问题非常相似: How to convert pugi::char_t* to string

我已经为这个问题苦苦挣扎了一段时间,作为一个初学者,我真的不知道除了在这里问之外还能做什么,所以如果这算作重复,我很抱歉。

pugi::xml_node actors = source_file.child("scene").child("actors");
std::vector<const char*> actor_db;
for (pugi::xml_node actor = actors.first_child(); actor; actor =     actor.next_sibling())
{
  const char *a = *actor.child_value();
  actor_db[actor.attribute("id").as_int()] = a;
}

a value of type "pugi::char_t" cannot be used to initialize an entity of type "const char *"

行 const char *a = *actor.child_value();是我尝试将 const char_t* xml_node::child_value() 的 return 值转换为 const char*.

的糟糕尝试

我希望 actor.child_value() 的值存储在 const char* 中,然后放入向量 actor_db.

pugi::char_t 是 char 或 wchar_t 类型,具体取决于配置。我已将其设置为 pugi::char_t 将是一个字符。

我知道这可能是一个简单的错误,但即使经过我广泛的搜索和类似的 SO 问题,我仍然无法解决我的问题。

I want the value of actor.child_value() to be stored in a const char* then put inside of the vector actor_db.

不,你不知道。唯一可以存储"in"一个const char*的是一个字符数组的位置。它实际上不是一个字符串,而是一个 指向字符串 的指针。指针的容器充满了问题。

存储 std::vector<std::string>,然后使用您链接到的问题的答案1 中的代码,以获得 std::string

1 其中,奇怪的是,我刚刚注意到我几年前写的。 :D