How do i store a cin value to two different variables?
this is what i did but its not working.
21 Replies
I assume you don't actually want both the variables to contain the same thing?
Depending on what exactly you are trying to read here, you could set a delimiter to read what you want
yeah its gonna take in a month/year
and they are seperated by a /
So read until the / to get the month
And then read until the end of the line to get the year
so this?
yeah no that does not work
Oh, that's not what I meant
The thing with using cin.ignore('/') first is that it will read and discard everything until it finds the '/'
So I have to use cin.ignore(‘\n’) in the same line to ignore the end of the line ?
ignore does not ignore one thing. It ignores everything until it find what you specify
So I don’t want it to ignore the first two numbers before /
Yea, you want to read those number before you ignore the '/'
cin>>variable1>>cin.ignore(‘/‘)>>variable2 ?
I am not sure if that syntax will work but that is what you want to do
Actually that might not work since the first argument to ignore() is supposed to be the number of characters you want to ignore
this works for me but the assignment says i need to do this all in one line
is there a short form for this?
Haven't done c++ in a while but you can't chain these?
my c++ knowledge is about 1 month. whats a chain?
unless chaining is c program thing as well then its my fault
Like this cin >> tempExpMon >> cin.ignore(...rest of code
Same way you have put the ignore and tempExpYear on one line
Though if that doesn't work, you could read that character into something else I suppose
yeah i get this when i try that
Ah, so it isn't possible to do that. Unfortunate
oh well it works the other way so its all good
thanks for all the help