UNICODE下CString转string
真搞不懂,为毛C++这么多类型转换。。CString m_str(_T("fuck conversion"));
char *chr=new char;
WideCharToMultiByte(CP_ACP,0,m_str.GetBuffer(),-1,chr,m_str.GetLength()+1,NULL,NULL);
string str=chr;
cout<<str;
2、char转string
char ch = {0};
itoa(i, ch, 10);
std::string str = (char *)ch;
3、int转byte
public byte[] intToByte(int i) {
byte[] abyte0 = new byte;
abyte0 = (byte) (0xff & i);
abyte0 = (byte) ((0xff00 & i) >> 8);
abyte0 = (byte) ((0xff0000 & i) >> 16);
abyte0 = (byte) ((0xff000000 & i) >> 24);
return abyte0;
}
4、byte转int
publicstatic int bytesToInt(byte[] bytes) {
int addr = bytes & 0xFF;
addr |= ((bytes << 8) & 0xFF00);
addr |= ((bytes << 16) & 0xFF0000);
addr |= ((bytes << 24) & 0xFF000000);
return addr;
}
页:
[1]