C ++:此运算符^是什么? [英] C++ : what is this operator ^?

查看:64
本文介绍了C ++:此运算符^是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main(){

int main() {

std::string original = "Hello world";
std::string decrypted;
std::string encrypted;
char key = 'x';

cout << "Original string: " << original << endl << endl;

for(int i=0;i<original.size();i++)
{
    encrypted += original[i] ^ ((int)key + i) % 20;
}

cout << "Encrypted string: " << encrypted << endl << endl;

cin.get();
return 0;

}

我在youtube上找到了此加密程序,但我不知道这行代码的作用->加密+ =原始[i] ^((int)密钥​​+ i)%20;.这是什么^运算符,它的作用是什么?我以为它仅用于将数字升为幂.此外,当我将该行更改为加密=加密+原始[i] ^((int键+ i)%20;我收到错误"std :: operator中的运算符不匹配",为什么?

I found this encryption program on youtube and i don't know what this line of code does-->encrypted += original[i] ^ ((int)key + i) % 20; . What is this ^ operator and what does it do exactly?I thought it was only used for raising a number to a power.Also when i change this line to encrypted = encrypted + original[i] ^ ((int)key + i) % 20; i get error "no match for operator in std::operator" , why is that?

对不起,我的英语,谢谢.

Sorry for my english and thanks in advance.

推荐答案

在C ++中, ^ 是异或或XOR函数.您可以在此处了解更多信息.

In C++, ^ is the exclusive or, or XOR function. You can read more about it here.

这篇关于C ++:此运算符^是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆