C++ 我想显示用c+编写的程序的输出+;到xml文件
产量。。。。。。。。 ...........C++ 我想显示用c+编写的程序的输出+;到xml文件,c++,xml,C++,Xml,产量。。。。。。。。 ........... 像这样的东西Tinyxml非常容易使用,而且它是免费的,或者如果它是一个简单的XML布局,您可以自己编写 XML文件只是具有特殊格式和控制字符的文本文件 P>不需要更多的信息来说明你想要的是什么,或者C++库或你使用的版本,很难直接给你建议。 比如说,你想要这样的东西吗 int countNodes( TreeNode *root ) { // Count the nodes in the binary tree to whi
像这样的东西Tinyxml非常容易使用,而且它是免费的,或者如果它是一个简单的XML布局,您可以自己编写
XML文件只是具有特殊格式和控制字符的文本文件 <> P>不需要更多的信息来说明你想要的是什么,或者C++库或你使用的版本,很难直接给你建议。 比如说,你想要这样的东西吗
int countNodes( TreeNode *root ) {
// Count the nodes in the binary tree to which
// root points, and return the answer.
if ( root == NULL )
return 0; // The tree is empty. It contains no nodes.
else {
int count = 1; // Start by counting the root.
count += countNodes(root->left); // Add the number of nodes
// in the left subtree.
count += countNodes(root->right); // Add the number of nodes
// in the right subtree.
return count; // Return the total.
}
} // end countNodes()
您的问题不清楚,所以我猜您想“将数据输出到XML文件中” 以XML格式将数据输出到文件流中可能类似于:
<RootNode>
<Node>
<Property Name="Node1"/>
<Node>
<Property Name="Sub-node1">
</Node>
<Node/>
<Node Name="Node2"/>
</RootNode>
#包括
#包括
int main(int argc,char*argv[])
{
TreeNode*root=DOWhatAveragezMoYouwanttoCreateThit();
int count=countNodes(根);
删除根;
std::fstream输出(“output.xml”,std::ios\u base::out)
output@paercebal:我想用xml显示一个二叉树程序的输出。我可以用简单的归档方式显示它,但我不知道xml的输出是什么?请也显示出来,这将有助于理解问题所在。我使用的是viusal studio 9,我想让我的程序生成上述内容。这个程序是动态的吗为树生成xml格式,否则我必须硬编码?你必须硬编码。如果你需要使用xml,那么你有几天/几周的时间来学习。一个简单的SO问题是无法解决的。按照链接,使用教程,直到你得到它。像我这样硬编码对于健壮的xml导出来说是错误的解决方案,除非你非常精通XML(你知道其中的暗处,等等),但它在某些方面会有所帮助。如果你想要一个健壮的解决方案,你需要使用能够输出数据的解析器。Xerces会出现在脑海中,即使它有点“大”。
#include <iotream>
#include <fstream>
int main(int argc, char * argv[])
{
TreeNode * root = doWhataverGizmoYouWantToCreateThat() ;
int count = countNodes(root) ;
delete root ;
std::fstream output("output.xml", std::ios_base::out)
output << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ;
output << "<count value=\"" << count << "\" />\n" ;
return 0 ;
}
<?xml version="1.0" encoding="utf-8" ?>
<!-- This is a comment -->
<!-- The first line will declare the XML file, as well as
its version, and its encoding -->
<my_element>
<!-- this is an element. It can contain others elements,
as well as text data and attributes -->
<my_other_element my_attribute="some_value" />
<!-- my_other_element has an attribute whose name is
my_attribute, and whose value is some_value -->
<my_another_element>Some text value</my_another_element>
<!-- my_another_element has an attribute whose content
is the following text "Some text value" -->
<my_element>
<!-- this is the end of my_element, closing it -->