Get bytes from std::string in C++

后端 未结 7 1250
遇见更好的自我
遇见更好的自我 2020-12-08 14:12

I\'m working in a C++ unmanaged project.

I need to know how can I take a string like this \"some data to encrypt\" and get a byte[] array which I\'m gonna use as the

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 15:12

    I dont think you want to use the c# code you have there. They provide System.Text.Encoding.ASCII(also UTF-*)

    string str = "some text;
    byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
    

    your problems stem from ignoring the encoding in c# not your c++ code

提交回复
热议问题