wstringstream 从 xml 文件到整数?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是时候进行一些疯狂的猜测了!
我敢打赌,您从
*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.