#include "stdafx.h" #using <mscorlib.dll> #include <tchar.h> using namespace system; #using <system.xml.dll> using namespace system::xml; // this is the entry point for this application int _tmain(void) { xmldocument* xmldoc = new xmldocument(); try { xmldoc->load("sample.xml"); system::console::writeline("document loaded ok." ); } catch (exception *e) { system::console::writeline("load problem"); system::console::writeline(e->message); } return 0; }
#using 语句非常重要。没有它,就会出现一些奇怪的编译错误,如'xml' : is not a member of 'system' 或 'xml' : a namespace with this name does not exist. 在c#或vb.net中,有一个project,add references 菜单项目自动为你完成这项工作,但是在c++中,编程者必须自己去完成。你可以在在线帮助中找到class或namespace汇编。