我在MSVC2008 MFC中遇到此问题.我正在使用unicode.我有一个函数原型:
MyFunction(const char *)
Run Code Online (Sandbox Code Playgroud)
我在说它:
MyfunFunction(LPCTSTR wChar).
Run Code Online (Sandbox Code Playgroud)
错误:无法将参数1从"LPCTSTR"转换为"const char*"
怎么解决?
可能重复:
将lptstr转换为char*
我需要转换LPTSTR p为CHAR ch[].我是C++的新手.
#include "stdafx.h"
#define _WIN32_IE 0x500
#include <shlobj.h>
#include <atlstr.h>
#include <iostream>
#include <Strsafe.h>
using namespace std;
int main(){
int a;
string res;
CString path;
char ch[MAX_PATH];
LPTSTR p = path.GetBuffer(MAX_PATH);
HRESULT hr = SHGetFolderPath(NULL,CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, p);
/* some operation with P and CH */
if(SUCCEEDED(hr))
{ /* succeeded */
cout << ch;
} /* succeeded */
else
{ /* failed */
cout << "error";
} /* failed */
cin >> …Run Code Online (Sandbox Code Playgroud)