代码如下:
void LoggerProxy::SetSrcInfo(int nProductID, const char *sApp, const char *sVer, const char *sOpUser,
const char *sOpPath)
{
char sTmp[128];
memset(sTmp,0,sizeof(sTmp));
sprintf(sTmp,"<ProductID>%d</ProductID> <Name>%s</Name> <Version>%s</Version> \
<Description>%s</Description> <Status>",nProductID,sApp,sVer,sApp);
m_SrcInfoStarting=m_SrcInfoStarted=sTmp;
m_SrcInfoStarting+="0";
m_SrcInfoStarted+="1";
memset(sTmp,0,sizeof(sTmp));
sprintf(sTmp,"</Status> <OpUser>%s</OpUser> <OpPath>%s</OpPath> <RunType>*</RunType>",sOpUser,sOpPath);
m_SrcInfoStarting+=sTmp;
m_SrcInfoStarted+=sTmp;
// printf("m_SrcInfoStarting[%s]\nm_SrcInfoStarted[%s]\n",m_SrcInfoStarting.c_str(),m_SrcInfoStarted.c_str());
}
其中m_SrcInfoStarting、m_SrcInfoStarted为class LoggerProxy的成员变量、类型为string。将printf那句注释掉以后程序无法启动,调试core提示内存错误,将printf注释打开程序可以正常启动,请教大家这个问题是什么问题?谢谢大家。