C++ strlen 和 strncpy的问题

mediam2000 2009-04-01 11:36:06
编译环境:winxp + vs2005

#include <cstring>
using std::strlen;
using std::strncpy;

在我输入using std::的时候为什么不出现strlen的输入提示,
就是输入::后,strlen没有出现在下拉的选择框中,不然的话我只要选中需要的双击就可以了?
...全文
374 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dinelgua 2009-04-01
  • 打赏
  • 举报
回复
string.h 里的

strlen这种方法一看就不是std里的
mediam2000 2009-04-01
  • 打赏
  • 举报
回复
VS2005编译后:
1>c:\documents and settings\zhou xiaoming\my documents\visual studio 2005\projects\fig20_13\fig20_13\employee.cpp(17) : warning C4996: “strncpy”被声明为否决的
1> d:\program files\microsoft visual studio 8\vc\include\string.h(156) : 参见“strncpy”的声明


这段话是什么意思的?
  • 打赏
  • 举报
回复
是C的库,直接用,没有名字空间这会事的。
Paradin 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chin_chen 的回复:]
strlen不是std命名空间里面的,
它是c中cstring里面的。
[/Quote]
.
mengde007 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 mediam2000 的回复:]
#include "stdafx.h"

#include <iostream>
#include <string>
using namespace std;

#include "Date.h"
#include "Employee.h"

Employee::Employee(const char *const fn, const char *const ln, const Date dateOfHire, const Date dateOfBirth)
: hireDate( dateOfHire), birthDate( dateOfBirth )
{
int length = strlen( fn );
length = ( len…
[/Quote]
^^^
mediam2000 2009-04-01
  • 打赏
  • 举报
回复
#include "stdafx.h"

#include <iostream>
using std::cout;
using std::endl;

#include <cstring>
using std::strlen;
using std::strncpy;

#include "Date.h"
#include "Employee.h"

Employee::Employee(const char *const fn, const char *const ln, const Date dateOfHire, const Date dateOfBirth)
: hireDate( dateOfHire), birthDate( dateOfBirth )
{
int length = strlen( fn );
length = ( length < 25 ? length : 24 );
strncpy( firstName, fn, length); // vs2005编译后:employee.cpp(19) : warning C4996: “strncpy”被声明为否决的.什么意思?
firstName[ length ] = '\0';

length = strlen( ln );
length = ( length < 25 ? length : 24 );
strncpy( lastName, ln, length);
lastName[ length ] = '\0';

cout << "Employee object constructor: "
<< lastName << ' ' << firstName << endl;
}

void Employee::printEmp()
{
cout << lastName << ' ' << firstName ;
cout << " bithDate: ";
birthDate.displayDay();
cout << " hireDate: ";
hireDate.displayDay();
}
chin_chen 2009-04-01
  • 打赏
  • 举报
回复
strlen不是std命名空间里面的,
它是c中cstring里面的。
wangyadong 2009-04-01
  • 打赏
  • 举报
回复
你直接使用这个函数就行,不用using std
mengde007 2009-04-01
  • 打赏
  • 举报
回复
很明显,strlen不属于std;
sunnystone614 2009-04-01
  • 打赏
  • 举报
回复
被否决是个警告,程序还是能运行的,这个跟编译器有关,vs2005里面是不推荐使用strncpy方法,好像因为这个不易于调试,没有正确的报错,有点记不清了。
他推荐使用strncpy_s这个方法。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧