gpt4 book ai didi

C++:将 LPTSTR 转换为字符数组

转载 作者:太空狗 更新时间:2023-10-29 19:53:51 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Convert lptstr to 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 >> a;
return 0;
}

提前致谢。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com