LPTSTR与string互相转化 byte*和char
C/C++ code//这么写
#include<iostream>
#include<string>
#include<windows.h>
usingnamespacestd;
int main(intargc, CHAR*argv[])
{
LPTSTR lp="ddd";
string str=(string)lp;
cout<<str<<endl;
system("pause");return0;
}
这个对!
string str="dddd";
LPTSTR lp=const_cast<char*>(str.c_str());
cout<<lp<<endl;
这个也不错。
C++语言,用C++方法:
char a[] = "ab ";
BYTE* pByte = static_cast <BYTE*> (a);
因为BYTE: An 8-bit integer that is not signed
它和unsigned char可以安全转换.
char str[] = "abcdefg ";
Byte* lpBuffer = (Byte)str;