使用 strcpy_s 作为 TCHAR 指针(Microsoft 特定) [英] using strcpy_s for TCHAR pointer (Microsoft Specific)

查看:30
本文介绍了使用 strcpy_s 作为 TCHAR 指针(Microsoft 特定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪种方法是正确的?

I was wondering which is the correct way?

_tcscpy(tchar_pointer, _tcslen(tchar_pointer), _T("Hello World"));

_tcscpy(tchar_pointer, _tcsclen(tchar_pointer), _T("Hello World"));

_tcscpy(tchar_pointer, ???, _T("Hello World"));

推荐答案

tchar 指针来自外部,我这边不知道指针引用的缓冲区有多大

the tchar pointer are coming from external, and my side has no idea how large the buffer referred by the pointer is

如果是这样,那么这些都不是你想要的.

所有安全"函数的工作方式是告诉他们目标缓冲区有多大.

The way all the "safe" functions work is that you tell them how big the target buffer is.

你不知道吗?您不能使用这些功能.

You don't know? You can't use those functions.

int buffer_size = _tcslen(xxx) * sizeof(TCHAR)

不起作用.它将保证复制的字符串不长于缓冲区中已有的字符串.如果缓冲区没有被初始化,就会失败;如果缓冲区以 '\0' 开头,则不会复制任何内容;等等.

This will not work. All it will guarantee is that the string copied is not longer than whatever is already in the buffer. If the buffer has not been initialized, it will fail; if the buffer begins with a '\0', nothing will be copied; and so forth.

这篇关于使用 strcpy_s 作为 TCHAR 指针(Microsoft 特定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆