Converting string to tchar in VC++
Asked Answered
O

2

3

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?

Overlord answered 8/12, 2013 at 14:57 Comment(2)
possible duplicate of Convert string to TCHAR* in VC++?Galliard
i have compiler error C2440: '=' : cannot convert from 'TCHAR *' to 'TCHAR [16]'Overlord
D
8
#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.

Dapple answered 8/12, 2013 at 15:5 Comment(2)
This gives me Error: no instance of overloaded function "wcscpy_s" matches the argument listSuntan
that's perfect. Thank youReasoning
P
1

You may try like this:

#include <atlstr.h>
_tcscpy_s(szProxyAddr, CA2T(internetprotocol.c_str()));
Puzzlement answered 8/12, 2013 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.