問題描述
我參加有競爭力的節目。鑒于我迫切需要一個必不可少的模板來記憶,我非常使用宏。
例如,我使用
#define large long long
large value;
不過,有兩個運算子讓我很惱火:輸入<<和>>輸出。
期待
我想看到類似的東西
#include <iostream>
using namespace std;
#define and <<
#define with >>
#define print cout
#define input cin
int main() {
long long value1, value2;
input value1 with value2;
print value1 and value2;
}
我希望這個程式能夠回顯用戶輸入的兩個整數值。
問題
但是,我經常收到一條錯誤訊息,指出Cannot #define something as an operator. 我該如何解決?如果我不能,有替代品#define and <<嗎?我非常感謝您的回復。
uj5u.com熱心網友回復:
<<將宏擴展為運算子(例如or >>、example)是完全合法的(盡管令人作嘔)。您只是不能and用作宏的名稱,因為and它是關鍵字。
因此,如果您堅持走這條路線,只需選擇不在關鍵字串列中的其他名稱即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/493796.html
標籤:C
