简体   繁体   中英

How can I convert a string into a byte array in c++?

How can I convert this C# code to C++?

string map = "maps\guardian";
byte[] mapName = Encoding.ASCII.GetBytes(map);

Use std::string like this

std::string myString("Hello World!");
const char* myConstArray = myString.c_str();
char myNonConstArray[100];
strcpy(myNonConstArray, myString.c_str());

both const and non-const versions there.

Would not this suffice?:

std::string map = "maps\guardian";
char* asciimap = map.c_str();

In C++ there is no byte type. You only have char .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM