写俩个例子给你看看
#include
#include
#include
using namespace std;
int main()
{
string s = "测试test string to byte程序";
int slen = s.size();
cout << "s is " << slen << " bytes." << endl;
BYTE *p;
p = new BYTE[slen+1];
p[0] = 'c';
p[1] = '+';
p[2] = '+';
p[3] = '\0';
p[slen] = '\0';
cout << "str in BYTE array is:" << endl;
cout << p << endl;
char *m = (char *)s.c_str();
char *n = (char *)p;
while(*m)
{
*n = *m;
n++;
m++;
}
*n = '\0';
cout << "str in BYTE array is change:" << endl;
cout << p << endl;
delete p;
return 0;
}
/*
#include
#include
#include
using namespace std;
int main()
{
string s = "测试test string to byte程序";
int slen = s.size();
cout << "s is " << slen << " bytes." << endl;
BYTE *p;
p = new BYTE[slen+1];
p[0] = 'c';
p[1] = '+';
p[2] = '+';
p[3] = '\0';
p[slen] = '\0';
cout << "str in BYTE array is:" << endl;
cout << p << endl;
s.copy((char *)p, slen, 0);
cout << "str in BYTE array is change to:" << endl;
cout << p << endl;
delete p;
return 0;
}
*/