Does #define work? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Does #define work?

Hey, i was wondering, does #define work? I tried many times to define cin as something else but it doesn't work. I also code on PC and I use it quite often so that's why I asked. Can anyome help me?

15th Oct 2017, 1:04 PM
MEDO capra
MEDO capra - avatar
7 Antworten
+ 8
@MEDO capra The problem is with your code, not the #define directive. cin<<x is invalid, it should have been cin>>x. Thus, replace your #define with this one: #define in(x) cin>>x
15th Oct 2017, 1:59 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 23
15th Oct 2017, 1:18 PM
Nithiwat
Nithiwat - avatar
+ 20
A funny example! #include <iostream> using namespace std; #define br cout << endl int main() { cout << "MEDO capra was a great guy for "; br; cout << "50 years!"; } [http://cpp.sh/6m6tb]
15th Oct 2017, 1:23 PM
Babak
Babak - avatar
+ 19
#include <iostream> using namespace std; #define br cout << endl #define in(x) cin >> x; int main() { int n = 0; cout << "MEDO capra was a great guy for "; br; cout << "50 years!"; br; cout << "How many tears?! "; in(n); cout << "Ahhhh... " << n << " years"; } :DDDDD
15th Oct 2017, 1:41 PM
Babak
Babak - avatar
+ 2
Well thanks but I meant to say if it works in the Solo Learn playground.
15th Oct 2017, 1:11 PM
MEDO capra
MEDO capra - avatar
+ 2
Well... if you define cin as something else it doesn't work https://code.sololearn.com/cNtZ8aB7PIbY/?ref=app
15th Oct 2017, 1:23 PM
MEDO capra
MEDO capra - avatar