I am trying to use a C++ string as the key for xoring another string.
The program crashes with (0xC0000005) Access violation.
Though it works if the key is declared as char key[260].
Code:#include <iostream> #include <string> using namespace std; int main() { string buf = "Value with the position of a character within"; string key = "Ak!$s**s1z*z*z*z*abjkvyuildoin*ek-+qsdfghjjop"; string out; int arrSize = buf.length(); for(int i = 0; i < arrSize; i++) { out[i] = buf[i] ^ key[i]; } cout << "String size: " << arrSize << endl; cout << "String encrypt: " << buf << "\n\n"; for(int i = 0; i < arrSize; i++) { buf[i] = out[i] ^ key[i]; } cout << "String decrypt: " << buf << endl; cout << "Key: " << key << endl; return 0; }