Converting string to tchar in VC++

僤鯓⒐⒋嵵緔 提交于 2019-12-17 21:08:05

问题


how I can convert string to tchar in VC++?

string internetprotocol="127.4.5.6";

 TCHAR szProxyAddr[16]; 

i want to set:

szProxyAddr=internetprotocol;

how i can do it?


回答1:


#include <atlstr.h>


string internetprotocol="127.4.5.6";
TCHAR szProxyAddr[16]; 

_tcscpy_s(szProxyAddr, CA2T(internetprotocol.c_str()));

_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.

Be careful with destination variable length.




回答2:


You may try like this:

#include <atlstr.h>
_tcscpy_s(szProxyAddr, CA2T(internetprotocol.c_str()));


来源:https://stackoverflow.com/questions/20454793/converting-string-to-tchar-in-vc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!