你的問題不清楚,所以我想你想「輸出數據到XML文件」
Outputing數據轉換成XML格式的文件流可能是這樣的:
#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 ;
}
請閱讀的iostream幫助有關fstream的對象及其用途的詳細信息:
http://www.cplusplus.com/reference/iostream/
現在,如果您想分析和修改現有的XML,您將需要一個XML解析器。您可以在google的解析器,例如有:
http://www.google.com/search?q=XML+c%2B%2B+parser
編輯:
看完後評論:
XML是一種有組織的文本文件。有點像HTML,如果是關於元素,屬性和數據。例如,這是一個XML文件內容:
<?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 -->
欲瞭解更多信息,請閱讀:
http://www.google.com/search?q=XML
無文字?沒有解釋? – paercebal 2010-09-01 07:44:42
@paercebal:我想在xml中展示一個二叉樹程序的輸出。 – nomi 2010-09-01 07:46:34
我可以將它展示到簡單的文件夾中,但我不知道xml – nomi 2010-09-01 07:47:32