when l use "cin" to put some characters in c++,it always ends in an error . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

when l use "cin" to put some characters in c++,it always ends in an error .

Maybe l use wrong ways to run the cpp,can someone tell me how to use "cin" when run cpp.

27th Mar 2017, 9:02 AM
big brother w
big brother w - avatar
2 Answers
+ 13
write your code in code playground. save it as public. then we can help you.
27th Mar 2017, 10:04 AM
Agus Mei
Agus Mei - avatar
+ 10
Make sure your binary shift operator is facing the right direction. Cin requires the operator >>, while cout requires the operator <<. If you have the right operator, then make sure you're properly declaring the variable you're trying to put a value into. Make sure that variable is initialized, as either 0 or null if the variable is a normal variable or a pointer respectively. If that fails, check which scope you are using it in. Are you accessing from an inner scope to an outer scope, or are you accessing from an outer scope to an inner scope. If the latter then your doing it wrong. If worse comes to worse use #include <stdio.h> or the more C++ friendly #include <cstdio> and then set the variable to equal fgetc(stdin). That will allow you to get an input and set your variable to that input. Note, the value you put in must match the data type or you'll get a type error. <-- Cheers -->
27th Mar 2017, 3:02 PM
SoraKatadzuma
SoraKatadzuma - avatar