111,130
社区成员
发帖
与我相关
我的任务
分享
我这样写的话 TCHAR temp2[] = _T("hello"); // 报错:_T 未定义
//加上了头文件#include <TCHAR.h> 之后还是有问题
//报了:unexpected end of file in macro expansion
//cannot convert from 'const wchar_t [4]' to 'WCHAR [17]'
strcpy(TCHAR *, string.c_str())//将String赋与TCHAR
{
TCHAR temp1[129];
temp1 = "hello"; // <-- 错误,cannot convert from 'const char [6]' to 'WCHAR [129]'
TCHAR temp2[] = _T("hello"); // 定义并初始化,ok
TCHAR temp3[129];
StringCbCopy( temp3, 128, _T("hello") ); // 先定义空字符串,再用字符串拷贝的方式,ok
return 0;
// "hello" ASCII字符串
// L"hello" 宽字符串
// _T("hello") 根据当前的编译设定自动调整为ASCII或宽字符串
}
#include "stdafx.h"
#include <stdlib.h>
#include <vcclr.h>
using namespace System;
#define RAS_MaxDeviceName 31
typedef char CHAR;
int main(array<System::String ^> ^args)
{
String^ k = "ssss";
CHAR szDeviceName[ RAS_MaxDeviceName + 1 ];
pin_ptr<const wchar_t> wch = PtrToStringChars(k); // 取得宽字符指针(.Net托管string都是宽字符)
size_t cchConverted = 0;
size_t cbSize = sizeof(szDeviceName);
wcstombs_s( &cchConverted, szDeviceName, cbSize, wch, cbSize ); // 转化成ASCII(CHAR[]一般是ASCII字符串)
return 0;
}