C++ 在vc+;中加载xml值并将其传递到字符串中+;
我在vc++中工作,试图加载一个xml文件,并将整个数据加载到一个字符串中,但没有得到结果C++ 在vc+;中加载xml值并将其传递到字符串中+;,c++,visual-c++,xml-parsing,tinyxml,C++,Visual C++,Xml Parsing,Tinyxml,我在vc++中工作,试图加载一个xml文件,并将整个数据加载到一个字符串中,但没有得到结果 char text[700] = {""}; TiXmlDocument doc( "'demotest.xml" ); bool loadOkay = doc.LoadFile(); if ( !loadOkay ) { printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.Err
char text[700] = {""};
TiXmlDocument doc( "'demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
system("PAUSE");
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
printf( "** Printing via doc.Print **\n" );
//doc.Print( stdout );
{
printf( "** Printing via TiXmlPrinter **\n" );
TiXmlPrinter printer;
doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );
//upto this line its working fine in console. but when I convert this string am getting struck
wsprintf(text, "%s", (char*)printer.CStr());
AddLOG_message(text, 0, true);
}
最后两行我应该得到xml的全部内容,包括头、元素和值。
请帮忙。 < P>我这样做,用更少的C代码,更多的C++代码和刻划长度魔法数700的危险字符数组:
TiXmlPrinter printer;
doc.Accept( &printer );
doc.Print(); // simpler for stdout output
std::string text = printer.CStr(); // easier, safer this way
AddLOG_message( text.c_str(), 0, true );
非常感谢你。我的addlog_message函数是---------------->>>>>>无效addlog_message(char*message,int len,int add_time),如果我打印-->>char text[700]={“136”},我只得到136。我需要字符串中的完整xml结构。@user1441251您能生成参数
const char*message
?否则我的答案就不起作用了,您仍然需要char text[700]
,但是更容易strncpy(text,printer.CStr(),699)代码>我已经用这个字符映射了很多内容*。如果我更改为const char*,则会出现错误“const char与TCHAR类型的参数不兼容”void AddLOG_消息(const char*消息,int len,int add_time),请在这方面帮助我