[英]What does "and' mean in C++
我知道這已經在其他地方問過了,但是由於 and 運算符“&”與 C++ 中的實際單詞之間的歧義,我找不到它。 我正在學習 C++,並在hackerrank 中遇到了一個幫助函數,它有一行讓我感到困惑。
return x == y and x == ' '
我不確定“和”是做什么的。 谷歌搜索它只返回對“&”運算符的引用。
整個功能如下; “和”在第 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;
}
當開發人員使用不支持&&
或||
等字符的鍵盤時,會使用這些關鍵字 . 為這些運算符使用關鍵字將解決該問題。
在這種情況下and
與編寫&&
相同。
以下是關鍵字的完整列表:
和 &&
and_eq &=
位元&
比特|
補~
不是 !
not_eq !=
或 ||
or_eq |=
異或^
xor_eq ^=
and
是一個(不太知名的)C++ 替代運算符和&&
的同義詞。 它存在是因為 C/C++ 代碼可以用非 ASCII-7 字符集/編碼寫入文件。 因此,C/C++ 支持像&
、 ~
等運算符的替代命令。
請參閱:https ://en.cppreference.com/w/cpp/language/operator_alternative
編輯:編碼問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.