我正在尝试开展一个简单的图像加密项目,有几个问题想要问。
Should I store each byte of data from
ifstream
into a character like I did in my code?Each byte printed is a weird symbol (which is correct), but why does adding 10(an
int
) to that always results in a number when printed?int main() { vector <char> data; // Stores each byte from image.jpg ifstream fileIn("image.jpg", ios::binary); int i = 0; // Used for accessing each item in data vector while (fileIn){ //Add each character from the image file into the vector data.push_back(fileIn.get()); cout << "Original: " << data[i] << endl; // Print each character from image.jgp cout << "Result after adding: " << data[i] + 10 << endl; // This line is where I need help with i++; system("pause"); } fileIn.close(); system("pause"); return 0; }
输出:
Original: å
Result after adding: -112
Original: Æ
Result after adding: -100
Original:
Result after adding: 12
正如您所看到的,增加10总是会得到一个数字。我该如何正确地递增这些值,以便稍后可以将其更改回来?
感谢任何帮助。