wstringstream 从 xml 文件到整数?

发布于 2024-08-13 21:57:08 字数 388 浏览 8 评论 0原文

const XMLDataNode *pointsNode = node->GetChildren().at(0);
std::wistringstream pointsstrm(*pointsNode->GetInnerText());
pointsstrm >> loadedGame.points;

这是我编写的代码,用于从 XML 文件中提取 int 并将其传递到 loadedGame.points(一个 int)。但是,这不起作用。它可以编译,但没有给出正确的值。这是为什么? XMLDataNode 是一个操作 xmllite.dll 的类。

const XMLDataNode *pointsNode = node->GetChildren().at(0);
std::wistringstream pointsstrm(*pointsNode->GetInnerText());
pointsstrm >> loadedGame.points;

This is code I've written to pull an int from an XML file and pass it into loadedGame.points (an int). However, this isn't working. It compiles but doens't give the right value. Why is that? XMLDataNode is a class that manipulates xmllite.dll.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚你心 2024-08-20 21:57:08

是时候进行一些疯狂的猜测了!

我敢打赌,您从 *pointsNode->GetInnerText() 获得的文本并不是您想象的那样。您检查过它确实是您想要的文本吗?特别是,它可以包含空格吗?解析一个格式良好(即缩进、分成行等)的 XML 文件,而没有要引用的架构,这意味着所有涉及空格的文本节点最终都会出现在 DOM 树中。

Time for some wild guesses!

I'll bet you that the text you get from *pointsNode->GetInnerText() isn't what you think it is. Have you checked that it is indeed exactly the text you want? In particular, could it contain whitespace? Parsing a nicely formatted (i.e. indented, broken into lines, etc) XML file without a schema to reference ends up meaning that all sorts text nodes involving whitespace will end up in your DOM tree.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文