為什么我加上#include <string>就使用不了自己寫的strcopy()函式
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "assert.h"
#include <string>
//#include <cstring>
//using namespace std;
char * strcpy( char *strDest, const char *strSrc )
{
assert( (strDest != NULL) && (strSrc != NULL) );
char *address = strDest;
while( (*strDest++ = *strSrc++) != '\0')
{
return NULL;
}
return address;
}
int _tmain(int argc, _TCHAR* argv[])
{
char s1[6]="china" ;
char s2[3]="ch";
strcpy(s1,s2);
system("pause");
return 0;
}
為什么我加上#include <string>就使用不了自己寫的strcopy()函式 不理解
去掉#include <string>就可以編譯過
uj5u.com熱心網友回復:
string里面不是已經有了strcpy?uj5u.com熱心網友回復:
函式重名了,換個名字,或者將你自己的strcpy用namespace名字空間定義一下。uj5u.com熱心網友回復:
重名了 用命名空間定義一下,用;;作用域限定符指出所屬空間uj5u.com熱心網友回復:
不是我直接使用系統的strcopy()也會報錯uj5u.com熱心網友回復:
#include "stdafx.h"#include "stdio.h"
#include "stdlib.h"
#include "assert.h"
#include <string>
#include <cstring>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char s1[10] =“ww”;
char s2[3]="ch";
strcpy(s1,s2);
free(s1);
s1 = NULL;
system("pause");
return 0;
}
這樣也不行
uj5u.com熱心網友回復:
把自己寫的名字全改了。uj5u.com熱心網友回復:
最直接的方法,改你自己寫的函式名uj5u.com熱心網友回復:
報什么錯?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/131767.html
標籤:基礎類
