我知道这个问题已经在其他地方提出来了,但是由于and运算符“&”与C ++中的实际单词之间的歧义,我找不到它。我正在学习C ++,并在hackerrank中遇到了一个帮助函数,该函数使我感到困惑。
return x == y and x == ' '
我不确定“和”的作用。谷歌搜索它只会返回对“&”运算符的引用。
整个功能如下; “ and”位于第3行:
vector<string> split_string(string input_string) {
string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
return x == y and x == ' ';
});
input_string.erase(new_end, input_string.end());
while (input_string[input_string.length() - 1] == ' ') {
input_string.pop_back();
}
vector<string> splits;
char delimiter = ' ';
size_t i = 0;
size_t pos = input_string.find(delimiter);
while (pos != string::npos) {
splits.push_back(input_string.substr(i, pos - i));
i = pos + 1;
pos = input_string.find(delimiter, i);
}
splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
return splits;
}
答案 0 :(得分:1)
当开发人员使用不支持keytool
或-storetype PKCS12
等字符的键盘时,将使用这些关键字。为这些运算符使用关键字代替即可解决该问题。
在这种情况下,&&
与写||
相同。
以下是关键字的完整列表:
和&&
and_eq&=
bitand&
bitor |
compl〜
不是!
not_eq!=
或||
or_eq | =
xor ^
xor_eq ^ =
答案 1 :(得分:1)
and
是C ++替代运算符(未知),是&&
的同义词。之所以存在,是因为C / C ++代码可以用非ASCII-7字符集/编码写入文件中。因此C / C ++支持&
,~
等运算符的替代命令。
请参阅:https://en.cppreference.com/w/cpp/language/operator_alternative
编辑:编码问题