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.

Answers


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().

You can call c_str() to get a raw char array representing the string data as a c string.


You can use data() and memcpy() to copy all the bytes to another address, or access the bytes in the string by indexing the string object...

std::string x;
if (std::cin >> x) // note: read one whitespace-separated token, use getline for lines
{
    memcpy(p_dest, x.data(), x.size());  // to copy everything...
    // ...or...
    p_dest[offset] = x[i]; // copy one character, 0 <= i < x.size()
}

Need Your Help

Laravel 5.1 error in installation on windows 7 using xampp

laravel composer-php laravel-5.1

Hi can anyone help me to install laravel 5.1 on windows 7 using xampp? but in failed when im creating project, i already installed my composer