本文主要是介绍占位符解析@#,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
啊,简直要笨死了!!!!<img alt="大哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif" /><img alt="敲打" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/knock.gif" />
// XML解析.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
using namespace std;
/**************************************************************************
char *szPacket = "@szCamCode#@szDirect#@szTime#";
int main ()
{
<span style="white-space:pre"> </span>char *pcTemp;
<span style="white-space:pre"> </span>pcTemp = new char(128);
<span style="white-space:pre"> </span>memset (pcTemp,0,128);
<span style="white-space:pre"> </span>strcpy(pcTemp,szPacket);
<span style="white-space:pre"> </span>cout<<"the pcTemp is :"<<pcTemp<<endl;
<span style="white-space:pre"> </span>strcpy(pcTemp,"hello");
cout<<"the pcTemp is :"<<pcTemp<<endl; //可以直接覆盖
<span style="white-space:pre"> </span>getchar();
<span style="white-space:pre"> </span>return 0;
}
******************************************************************************/
char *szPacket = "@szCamCode#@szDirect#@szTime#.xml";
int main ()
{
<span style="white-space:pre"> </span>char *pcTemp =szPacket;
<span style="white-space:pre"> </span>//只是单纯的指针
<span style="white-space:pre"> </span>char *pcTemp1=NULL;
<span style="white-space:pre"> </span>char *pcTemp2=NULL;
<span style="white-space:pre"> </span>//保存数据
<span style="white-space:pre"> </span>char *ptr=new char[30]; // new char (30 ) ; error
do {
pcTemp1=strchr(pcTemp,'@');
cout<<"pcTemp1 is :"<<pcTemp1<<endl;
pcTemp2=strchr(pcTemp,'#');
cout<<"pcTemp2 is :"<<pcTemp2<<endl;
int len =strlen(pcTemp1)-strlen(pcTemp2);
cout<<"len is:"<<len<<endl;
strncpy(ptr,pcTemp1+1,len-1);
*(ptr+len-1)='\0';
cout<<"ptr is :"<<ptr<<endl;
<span style="white-space:pre"> </span> pcTemp=pcTemp2+1;
<span style="white-space:pre"> </span>}while (*(pcTemp2+1)!='.');
<span style="white-space:pre"> </span>system("pause");
<span style="white-space:pre"> </span>return 0;
}
这篇关于占位符解析@#的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!