如何将 pugi::char_t* 转换为字符串
你好 我正在使用 pugixml 来处理 xml 文档。我使用这种构造迭代节点,
pugi::xml_node tools = doc.child("settings");
//[code_traverse_iter
for (pugi::xml_node_iterator it = tools.begin(); it != tools.end(); ++it)
{
//std::cout << "Tool:";
cout <<it->name();
}
问题是 it->name() 返回 pugi::char_t* 并且我需要将其转换为 std::string。是否可以 ??我在 pugixml 网站上找不到任何信息
Hi
I'm using pugixml to process xml documents. I iterate through nodes using this construction
pugi::xml_node tools = doc.child("settings");
//[code_traverse_iter
for (pugi::xml_node_iterator it = tools.begin(); it != tools.end(); ++it)
{
//std::cout << "Tool:";
cout <<it->name();
}
the problem is that it->name() returns pugi::char_t* and I need to convert it into std::string. Is it possible ?? I can't find any information on pugixml website
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据手册,
pugi::char_t
是char
或wchar_t
,具体取决于您的库配置。这样您就可以在单字节(ASCII 或 UTF-8)和双字节(通常是 UTF-16/32)之间切换。这意味着您不需要将其更改为任何内容。但是,如果您使用
wchar_t*
变体,则必须使用匹配的流对象:并且,既然您要求,构造一个
std::string
或来自它的std::wstring
:或者,始终是
std::string
(这很少是您想要的!):希望这会有所帮助。
来源:粗略浏览一下“pugixml”文档。
According to the manual,
pugi::char_t
is eitherchar
orwchar_t
, depending on your library configuration. This is so that you can switch between single bytes (ASCII or UTF-8) and double bytes (usually UTF-16/32).This means you don't need to change it to anything. However, if you're using the
wchar_t*
variant, you will have to use the matching stream object:And, since you asked, to construct a
std::string
orstd::wstring
from it:Or, for always a
std::string
(this is rarely what you want!):Hope this helps.
Source: A cursory glance at the "pugixml" documentation.
您也可以使用 stringstream,
ps:不要忘记包含
you can use stringstream also,
ps: Don't forget to include