在C ++中创建XML时出现双引号错误 [英] Double quotes error while creating XML in C++

查看:62
本文介绍了在C ++中创建XML时出现双引号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是创建XML的代码

This is mine code to create XML

int _tmain(int argc, _TCHAR* argv[])
{
	char *xmldata = "<?xml version=1.0 encoding=UTF-8?><DataCaptureSesstings><ModuleSettings><account_id>1</account_id><capture_local_dir>c:\</capture_local_dir><capture_log_dir>c:\log</capture_log_dir><capture_log_level>debug</capture_log_level><capture_request_interval>2</capture_request_interval><capture_connection_interval>2</capture_connection_interval><smtp_server_name>n1</smtp_server_name><smtp_server_port>80</smtp_server_port><smtp_email_sender>s1</smtp_email_sender><smtp_email_sender_password>p1</smtp_email_sender_password></ModuleSettings><MachineList><Machine><MachineId>0022</MachineId><Make>Make1</Make><Model>Model1</Model><SerialNumber>SN1</SerialNumber><IpAddress>10.10.10.10</IpAddress><Port>80</Port></Machine><Machine><MachineId>3000</MachineId><Make>Make3</Make><Model>Model3</Model><SerialNumber>SN3</SerialNumber><IpAddress>30.30.30.30</IpAddress><Port>80</Port></Machine></MachineList></DataCaptureSesstings>";
	std::ofstream outfile ("sampleP2.xml");
	
	outfile << xmldata;

	outfile.close();
}



当我打开sampleP2.xml时,出现此错误



When i open the sampleP2.xml i am getting this error

A string literal was expected, but no opening quote character was found. Error processing resource 'file:///C:/Documents an...

<?xml version=1.0 encoding=UTF-8?><DataCaptureSesstings><ModuleSettings><account_id>1</account_id...


有什么错误吗?
使用char *时,以下解决方案很好,但可以使用CString str;


What''s the error?
With char* the below solution is fine but what to do with CString str;

推荐答案

版本和编码参数必须加引号:
The version and encoding parameters must be quoted:
char *xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>...";


这篇关于在C ++中创建XML时出现双引号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆