【发布时间】:2015-09-20 06:09:29
【问题描述】:
我的程序是:
#include <cstdio>
#include <cstring>
using namespace std;
int main(int argc,char **argv)
{
const static size_t maxbuf=128;
const char * s1="String one";
char sd1[maxbuf];
printf("length is %ld",strnlen(sd1,maxbuf));
return 0;
}
错误是:
strnlen was not declared in this scope
问题:
为什么我无法在我的 codeblocks IDE 上使用 C++ 中的
strnlen函数?他们是
strnlen的好替代品吗?
【问题讨论】:
-
你遇到了什么错误?
-
检查 strnlen 函数的定义位置并包含该库。
-
你为什么没有std::string-s?
-
strnlen() 是一个posix函数,cstring只提升标准C库函数。
-
你为什么不使用
std::string和std::cout等?