社区
C++ 语言
帖子详情
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
打赏
收藏
C++ strlen 和 strncpy的问题
编译环境:winxp + vs2005 #include using std::strlen; using std::strncpy; 在我输入using std::的时候为什么不出现strlen的输入提示, 就是输入::后,strlen没有出现在下拉的选择框中,不然的话我只要选中需要的双击就可以了?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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”的声明
这段话是什么意思的?
山的那边还是山~
2009-04-01
打赏
举报
回复
是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这个方法。
【C/
C++
】str函数族
strlen
、strcpy、strcat、strcmp、
strncpy
、strncat等函数的代码实现
本文详细解析了C/
C++
中常用的字符串处理函数如
strlen
、strcpy、strcat、strcmp、
strncpy
和strncat的实现原理与要点,涵盖功能说明、实现方法及安全注意事项,帮助开发者深入理解字符串操作机制,避免缓冲区溢出等
问题
。
纯C 字符串操作函数 实现 (strcpy,
strncpy
, memcpy, memset, strcat,
strlen
... )
本文深入探讨C/
C++
中的字符串操作函数实现细节,包括strcpy、
strncpy
、memcpy、memset、
strlen
、strcat、strcmp、strncmp和strchr等。不仅提供代码示例,还解析常见陷阱及效率
问题
。
strcpy和
strncpy
和memcpy和memmove四个函数对比分析
本文深入探讨了
C++
中字符串处理函数的使用,包括sizeof与
strlen
的区别,以及strcpy与
strncpy
的功能特性与潜在缺陷。通过代码示例展示了如何正确使用这些函数,并提供了安全替代方案,如memmove,以避免常见的内存覆盖
问题
。
C++
中有关于字符串的一些
问题
(
strlen
,sizeof,strcpy等)
本文详细介绍了
C++
中
strlen
和sizeof的区别,以及string、char*之间的转换。还讨论了strcpy、sprintf、memcpy三个函数的用途和安全性,指出strcpy可能导致的缓冲区溢出
问题
,以及
strncpy
的安全性但可能不添加
纯C 字符串操作函数 实现 (strcpy,
strncpy
, memcpy, memset, strcat,
strlen
... )
本文详细介绍了C/
C++
中常见字符串操作函数如strcpy、
strncpy
、memcpy、memset、
strlen
、strcat、strcmp、strncmp、strchr的实现原理与使用细节,特别强调了指针有效性检查、链式操作、src参数的const属性、'
C++ 语言
65,211
社区成员
250,514
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章