本文介绍了在 VC++ 中将字符串转换为 tchar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 VC++ 中将字符串转换为 tchar?
how I can convert string to tchar in VC++?
string internetprotocol="127.4.5.6";
TCHAR szProxyAddr[16];
我想设置:
szProxyAddr=internetprotocol;
我该怎么做?
推荐答案
#include <atlstr.h>
string internetprotocol="127.4.5.6";
TCHAR szProxyAddr[16];
_tcscpy_s(szProxyAddr, CA2T(internetprotocol.c_str()));
_tcscpy_s
是通用的 strcpy
版本,它适用于 Unicode 和多字符配置.CA2T
根据szProxyAddr
变量类型将const char*
转换为TCHAR*
.
_tcscpy_s
is generic strcpy
version which works both in Unicode and Multi-Character configurations. CA2T
converts const char*
to TCHAR*
, according to szProxyAddr
variable type.
注意目标变量长度.
这篇关于在 VC++ 中将字符串转换为 tchar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!