未定义标识符

1.未定义标识符bzero

① 首先添加头文件#include <string.h>

② linux下才有bzero(),windows下可以用memset()代替

#include <string.h>
// 将s中的前n个字节用ch替换并且返回s,
void *memset(void *s,int ch,size_t n)
 

memset清空数组:

memset(buffer, 0, sizeof(buffer)) // 这个函数在socket很常用。
char a[100];
memset(a, '/0', sizeof(a));  // 初始化数组。
memset清空结构体:

// 在一段内存块中填充某一个给定的值,常用于较大的对结构体和数组的清零操作。
struct sample_struct
{
    char csName[16];
    int iSeq;
    int iType;
};
memset(&stTest, 0, sizeof(struct sample_struct));

// 如果是数组:
struct sample_struct TEST[10];
memset(TEST, 0, sizeof(struct sample_struct)*10);


2.未定义标识符read

添加头文件 #include <io.h>

函数原型:

int read(int handle,void *buf,int len);

int handle:要读取文件

void *buf :要将读取的内容保存到缓冲区

int len :读取文件的长度

3.未定义标识符strcasecmp 和 strncasecmp

方案一:stricmp替换strcasecmp ;strnicmp替换strncasecmp,即可。

之后貌似还会报错:

   error C4996: 'strnicmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strnicmp. See online         help for details. D:\CAFFE_ROOT\src\caffe\common.cpp

解决办法:

这个问题在VS 2012之前的版本中是不会当做错误的,只是提出一个警告。为了避免报错,可以使用以下两个宏定义来屏蔽掉这种        错误。

在common.cpp文件的属性->c/c++->预处理器->预处理器定义   中添加:

    _CRT_SECURE_NO_DEPRECATE 

    _CRT_NONSTDC_NO_DEPRECATE 

方案二:用VC SDK中的函数来代替,在main函数外面步添加一下代码即可:

#ifdef _MSC_VER
#define strcasecmp stricmp
#define strncasecmp  strnicmp 
#endif


方案三:自己添加该函数的声明和定义

第一步:.h文件添加:

#ifdef _MSC_VER
int strcasecmp(char *s1, char *s2);
int strncasecmp(char *s1, char *s2, register int n);
#endif


第二步:.c文件中添加

#ifdef _MSC_VER
int strcasecmp(char *s1, char *s2)
{
   while  (toupper((unsigned char)*s1) == toupper((unsigned char)*s2++))
       if (*s1++ == '') return 0;
   return(toupper((unsigned char)*s1) - toupper((unsigned char)*--s2));
}
 
int strncasecmp(char *s1, char *s2, register int n)
{
  while (--n >= 0 && toupper((unsigned char)*s1) == toupper((unsigned char)*s2++))
      if (*s1++ == '')  return 0;
  return(n < 0 ? 0 : toupper((unsigned char)*s1) - toupper((unsigned char)*--s2));
}
#endif

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值