相关疑难解决方法(0)

c ++从LPCTSTR转换为const char*

我在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*"

怎么解决?

c++ types type-conversion

4
推荐指数
2
解决办法
2万
查看次数

C++:将LPTSTR转换为char数组

可能重复:
将lptstr转换为char*

我需要转换LPTSTR pCHAR 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)

c c++ lptstr visual-studio

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×2

c ×1

lptstr ×1

type-conversion ×1

types ×1

visual-studio ×1