Search code examples
c++memoryediting

String to Byte or Char* in C++


Okay, so I'm working on a memory editor in c++, I have a list of offsets and if I predefine what to change the offset too (0x68) then it works, but I was wondering if there was a way to convert string, as in, cin >> string, and it would split the string into bytes or char*s so it could use them in the offsets? Sorry if this doesn't make much sense.


Solution

  • The std::string class has two methods that can help you:

    • c_str(), that returns a \0-terminated char* string (AKA a "C"-style string);
    • data(), that returns the content of the string in a char const*, but without \0 termination; you have to retrieve the length separately with length() or size().