编译运行后,老是跳出一个提示框,提示“0x24581400”指令引用的“0xcccccccc”内存。该内存不能为“written”.
请高手求解#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;char* tiqu(char *dest, char *source)
{
char *str=dest;
while(*source)
{
if(*source=='#')
{
source++;
}
else
{
*dest++=*source++;
}
}
*dest='\0';
return str;}
int main(int argc, char* argv[])
{
char *oldW="#abc#d#e#f";
char *newW; tiqu(newW,oldW); cout<<newW; return 0;
}
请高手求解#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;char* tiqu(char *dest, char *source)
{
char *str=dest;
while(*source)
{
if(*source=='#')
{
source++;
}
else
{
*dest++=*source++;
}
}
*dest='\0';
return str;}
int main(int argc, char* argv[])
{
char *oldW="#abc#d#e#f";
char *newW; tiqu(newW,oldW); cout<<newW; return 0;
}
给分配下内存空间应该就没问题了
我给它赋了个值后,还是出问题。如,我赋值:char *newW=“a”;
char newW[100];
memset(dest,0,10);
没有初始化
{
char *oldW="#abc#d#e#f";
char *newW=new char[1000]; tiqu(newW,oldW); cout<<newW; return 0;
}
new ...
malloc ...