Finally someone who can explain well and not mouth breathe so much! thank you
@zelotypia78743 жыл бұрын
JESUS CHRIST, I have been puzzled by this for so long and ignored it until now but couldn't handle not knowing how to do it anymore. Just saved me a huge headache, thank you!
@alfredopozos69815 жыл бұрын
BLESS YOUR SOUL JUST KNOWING THAT I COULD DO "== false" HELPED ME SOLVE MY LAB. THANK YOU. DEF SUBSCRIBED AND LIKED
@islandwoodfired5 жыл бұрын
14:39 "gotta do a bunch of shit..." sounds about right...lol
@tohruoikawa17135 жыл бұрын
God bless you man ! this video is seriously underrated .........................................
@SB-ls7qj2 жыл бұрын
"We try to crash everything, go crazy apeshit--" lmao
@LunaFlahy2 жыл бұрын
Thank you, man! Very professional!
@guilhermecampos8313 Жыл бұрын
Simple and very good solution. Thanks.
@latronix-omnigenus2 жыл бұрын
Actually setw(1) isn’t doing anything in your code. It’s working because of flushing cin (clear & ignore). Setw is not a good implementation because an app might ask the user for arbitrary numbers, so setting it to a specific width is not good. You cin.clear() to unset the failbit (so you no longer get cin.fail() == true or !cin.good as true in your case). The proper way to do cin.ignore now is like: cin.ignore(std::numeric_limits::max(), ‘ ’) You do have a better alternative, instead of adding clear & ignore after the if statement, you can do this: if (!cin.good() || cin.peek() == ‘ ‘). Peek will check a whitespace. This will force the error if a user types 1(space)2 instead of just assuming that the correct input is 1 and ignoring 2. std::isspace() would not be an option because it also gets the newline. Your error messages should go in cerr instead of cout. Do note that my answer is by no means a “great” implementation. Properly sanitizing content and handling input is a very tedious task. You should probably use a library for this or take the input as strings and properly handle it. Also you need to account for locale and Unicode characters.
@loveandpeace82714 жыл бұрын
maaaaan you're a geniuuuuus thanks sooo mucho, i really mean it , with this u are helping me a lot and i really appreciate it
@dillonfleharty53192 жыл бұрын
What if I want it to not allow floating point numbers?
@abuzharrluqman93044 жыл бұрын
BOYYYYY IM HERE 2020!!! TQ FOR SHARING THIS!!!!
@TJKhara6 жыл бұрын
Hi Suraj, This code works really well. Saved me from quite a bit of headache. Do you think you could go over in a bit more detail was you teach at the end of the video with making the menu with templates so that it is not restricted to any type?
@SurajSharmaFourKnob6 жыл бұрын
Thanks for the comment! Sadly I can't get into templates in detail yet like I said in the video. Not everyone might be ready for it yet. I will go through templates a little later in the tutorial.
@TJKhara6 жыл бұрын
Okay great. Yea whenever it makes sense. Look forward to it.
@god-of-creation60402 жыл бұрын
is there a way to not accept string input from a keyboard using a c++ function
@kamilosok44544 жыл бұрын
Can you make video about input validation in classes?
@SurajSharmaFourKnob4 жыл бұрын
Hey man I'll see what I can do :)
@kamilosok44544 жыл бұрын
@@SurajSharmaFourKnob Thanks
@RCPorter922 жыл бұрын
I used this in a class project and it works for the most part. However, I found that if you are looking for an integer value and the user inputs a floating point it accepts it and then does some craziness in key buffer that caused my program to skip the next input attempt entirely.
@hengjiuxiao3 жыл бұрын
Bless you for this great video!
@jaymob50375 жыл бұрын
Hear me out pls... i want to clear again if i wrote 213abc.... i dont want the system not to read the abc.. i want it to ask again... pls help
If you aren't checking for errors in input it will crash sadly, but check for my tutorials on input handling :) If the stream is expecting an integer, and you give it a string or anything else, it will either truncate the decimal, or crash altogether. Also, great question!
@MrThedrphil6 жыл бұрын
Great video! Thank you for posting!
@cesarluiz60282 жыл бұрын
U R MY HERO!!!!!
@MoeDouHamitou3 жыл бұрын
do i have to keep using std:: or can i just start with cout without the std::
@edwardibarra76653 жыл бұрын
i believe if you put the following: using namespace std; before int main you wont have to type std:: anymore and it'll let you run it perfectly fine
@amymathews46393 жыл бұрын
Good sir, God bless you. You really helped me out with my project!
@ARYANKUMAR-yc5tc4 жыл бұрын
Sir please help me! I've coded ifelse statement for my code. I code if(n=='aryan') cout
@UvUtkarsh4 жыл бұрын
Bro it is just because you have written Aryan in single quotes ('Aryan') use double quotes ("Aryan") Although I am replying very late but still😀
@Gulemo3 жыл бұрын
Thanks, nice video.
@TJKhara6 жыл бұрын
Hi Suraj, Quick question on this code. Is there a way to prevent the user from entering a double? I mean if we are expecting 2, right now the code will accept 2.23 as 2. Is there a way to ask the user again to enter an int only and not a double? Thanks.
@SurajSharmaFourKnob6 жыл бұрын
Hmm.. well the choice variable is an integer so it will never allow a double, and even if the user inputs it the data will be converted into an integer so there is no way a double can be accepted :) Although there might be a way to cin.peek() it.. I will look into it, otherwise if you find something please do tell me about it! Thanks for the support as always!
@yulianaluis6105 Жыл бұрын
thanks great video
@rand74383 жыл бұрын
If I want intger to be only from 1-8 where should I put the condition?
@TJKhara6 жыл бұрын
Thank you Suraj! Excellent video... will this work is the user just hits a bunch of line returns also? Like :)
@_daniel.w6 жыл бұрын
Yea it will :)
@_daniel.w6 жыл бұрын
But I mean, try it :)
@SurajSharmaFourKnob6 жыл бұрын
It does work but it does not complain, it just waits until something valid comes along since a line return is not really a bad input in that sense :)
@TJKhara6 жыл бұрын
Tried it... works great :)
@qwett63484 жыл бұрын
Thanks 👍
@sebastianm64075 жыл бұрын
Great! Thank you so much! :D
@sinisakesic76406 жыл бұрын
This is really useful thanks m8! Can u teach us how to use cin in classes and arrays with user's input?
@_daniel.w6 жыл бұрын
Well, using the input stream in a class in exactly the same, no different. But obviously put the "std::cin" in a function inside of a class :)
@SurajSharmaFourKnob6 жыл бұрын
You can do like Vitex said :) Although I will make sure to include an example of this in the coming videos!
@TJKhara6 жыл бұрын
I think things just make more sense when Suraj explains them :)
@sinisakesic76406 жыл бұрын
That'll be wonderful Suraj, thanks! ^^
@shiitytrolly29626 жыл бұрын
Thanks Bro! Liked and Subscribed❤
@SurajSharmaFourKnob6 жыл бұрын
Thanks so much!
@bruhmomento_21974 жыл бұрын
by any chance do you have the code for the function getchoice?
@SateLight4 жыл бұрын
Can this code be used for an array? Anyway thanks for the video
@שירהצדוק-ב6ג4 жыл бұрын
you are amazing thank you so much
@PontusOzzyA5 жыл бұрын
you have to use "==false" for it to work, at least for me and another dude in the comment section. thx.