How to convert a string literal to unsigned char array in visual c++

后端 未结 8 1530
闹比i
闹比i 2020-12-06 06:02

How to convert a string to Unsigned char in c++...

I have,

unsigned char m_Test[8];

I want to assign a string \"Hello world\"

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 06:36

    You can use strcpy:

    unsigned char m_Test[8];
    strcpy((char*)m_Test, "Hello world");
    

    Note that "Hello world" is too long for 8 bytes, so you will probably get a segfault.

提交回复
热议问题