wcscat_s、_tcscat_s异常

errno_t strcat_s(
   char *strDestination,
   size_t sizeInBytes,
   const char *strSource 
);
errno_t wcscat_s(
   wchar_t *strDestination,
   size_t sizeInWords,
   const wchar_t *strSource 
);

--------------------------------------------------

char buf[16];
strcpy_s(buf, 16, "Start");
strcat_s(buf, 16, " End");                          // Correct
strcat_s(buf, 16 – strlen(buf), " End");    // Incorrect

--------------------------------------------------

//240TCHAR
TCHAR szDirPre[23] = {_T("一二三四五六七八九十")};
//17个TCHAR
TCHAR szFileName[10] = _T("1�ʹ�����9");

//正常
if(0)
{
	int size = sizeof(szDirPre)/sizeof(TCHAR);
	_tcscat_s(szDirPre, size, szFileName);
}

//正常 - 错误代码
if(0)
{
	int size = sizeof(szDirPre)/sizeof(TCHAR);
	int length1 = _tcslen(szDirPre);
	int remain = size - length1;
	int length2 = _tcslen(szFileName);
	_tcscat_s(szDirPre, remain*sizeof(TCHAR), szFileName);
}

//异常
if(0)
{
	int size = sizeof(szDirPre)/sizeof(TCHAR);
	int length1 = _tcslen(szDirPre);
	int remain = size - length1;
	int length2 = _tcslen(szFileName);
	_tcscat_s(szDirPre, remain, szFileName);
}

//异常
if(0)
{
	_tcscat_s(szDirPre, sizeof(szDirPre), szFileName);
}

//正常
if(0)
{
	int endIndex = _tcslen(szDirPre);
	memcpy(szDirPre+endIndex, szFileName, _tcslen(szFileName)*sizeof(TCHAR));
	endIndex += _tcslen(szFileName);
	szDirPre[endIndex] = _T('\0');
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录 1 正文 3 一、 C++的string的使用 3 1.1 C++ string简介 3 1.2 string的成员 3 1.2.1 append 3 1.2.2 assign 4 1.2.3 at 4 1.2.4 begin 5 1.2.5 c_str 5 1.2.6 capacity 5 1.2.7 clear 6 1.2.8 compare 6 1.2.9 copy 6 1.2.10 _Copy_s 6 1.2.11 data 6 1.2.12 empty 6 1.2.13 end 6 1.2.14 erase 6 1.2.15 find 6 1.2.16 find_first_not_of 7 1.2.17 find_first_of 8 1.2.18 find_last_not_of 8 1.2.19 find_last_of 8 1.2.20 get_allocator 8 1.2.21 insert 8 1.2.22 length 8 1.2.23 max_size 8 1.2.24 push_back 8 1.2.25 rbegin 8 1.2.26 rend 8 1.2.27 replace 8 1.2.28 reserve 10 1.2.29 resize 11 1.2.30 rfind 11 1.2.31 size 11 1.2.32 substr 11 1.2.33 swap 11 1.3 string的构造 11 1.4 string的重载运算符 12 1.5 string与algorithm相结合的使用 12 1.5.1 string与remove 12 1.5.2 string与unique、sort 12 1.5.3 string与search 12 1.5.4 string和find、find_if 13 1.5.5 string与copy、copy_if 13 1.5.6 string与count、count_if 14 1.6 string与wstring 14 1.6.1 简介 14 1.6.2 wstring实例 15 1.6.3 wstring与控制台 15 1.6.4 string与wstring的相互转换 16 1.7 string与C++流 21 1.7.1 C++流简介 21 1.7.2 string与iostream、fstream 21 1.8 格式化字符串 22 1.8.1 简单常用的C方法 22 1.8.2 boost的方法 22 1.9 string与CString 23 二、 boost字符串算法库 23 2.1 boost字符串算法库导论 23 2.1.1 boost.algorithm.string是什么? 23 2.1.2 相关 23 2.1.3 boost.range导论 23 2.1.4 boost.regex导论 23 2.1.5 boost.algorithm.string的DNA 24 2.2 boost字符串算法解密 24 2.2.1 修剪(trim.hpp) 24 2.2.2 转换(case_conv.hpp) 26 2.2.3 判断式、断言函数(predicate.hpp)【Predicates】 27 2.2.4 查找 28 2.2.5 删除和替换 29 2.2.6 分割和组合 31 2.2.7 其它 32 三、 C字符串 32 3.1 C字符串常用算法 32 3.1.1 strcpy wcscpy 32 3.1.2 strcat wcscat 32 3.1.3 strchr wcschr 32 3.1.4 strcmp wcscmp 33 3.1.5 stricmp wcsicmp 33 3.1.6 strlen wcslen 33 3.1.7 strlwr/_strlwr wcslwr/_wcslwr 33 3.1.8 strncat wcsncat 33 3.1.9 strcspn wcscspn 33 3.1.10 strdup/_strdup wcsdup/_wcsdup 34 3.1.11 strncpy wcsncpy 34 3.1.12 strpbrk wcspbrk 35 3.1.13 strrev/_strrev wcsrev/_wcsrev 35 3.1.14 strset/_strset/_strset_l wcsset/_wcsset/_wcsset_l 35 3.1.15 strstr/wcsstr 35 3.1.16 strtok/wcstok 36 3.1.17 strupr/_strupr wcsupr/_wcsupr 36 3.2 更安全的C字符串函数 36 3.2.1 简述 36 3.2.2 简单实例 36 3.2.3 定制 38 3.2.4 兼容 41 3.3 通用字串函数 47 3.3.1 简述 47 3.3.2 简单实例 47 3.3.3 映射表 48 3.4 API级的字符串处理 48 3.4.1 简述 48 3.4.2 旧的API 48 3.4.3 Shell字符串函数 48 3.4.4 新的安全版字符串处理API 48 四、 C++字符串使用的建议 51 附录1:参考资料: 51 附录2: MSSTL中basic_string的部分源码解读 51 2.1 string的allocator 51 2.1.1 Allocate和Deallocate 51 2.1.2 allocator的泛型实现 52 2.1.3 string与char_traits 54 2.1.4 以char和wchar_t特化char_traits 56 附录3:Boost.Format中文文档 57 2.1 大纲 57 2.2 它是如何工作的 57 2.3语法 58 2.3.1 boost::format( format-string ) % arg1 % arg2 % ... % argN 58 2.3.2 printf 格式化规则 59 2.3.3 新的格式规则 60 附录4 TCHAR.h 映射表 60
提供的源码资源涵盖了小程序应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值