Search
Setup for Free
CP-SPC
Computer Programming - Seneca Polytechnic College
•
4y ago
Revan
How do i store a cin value to two different variables?
this is what i did but its not working
.
Computer Programming - Seneca Polytechnic College
Join
Welcome to Seneca Polytech's Programming Community! 🚀 Whether you're into CPA or CPP, all programs are welcome!
2,316
Members
View on Discord
Similar Threads
Was this page helpful?
Yes
No
© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
E
Eakam
•
9/30/22, 11:01 PM
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
R
Revan
OP
•
9/30/22, 11:01 PM
yeah its gonna take in a month
/year
R
Revan
OP
•
9/30/22, 11:01 PM
and they are seperated by a
/
E
Eakam
•
9/30/22, 11:01 PM
So read until the
/ to get the month
E
Eakam
•
9/30/22, 11:02 PM
And then read until the end of the line to get the year
R
Revan
OP
•
9/30/22, 11:05 PM
so this
?
R
Revan
OP
•
9/30/22, 11:07 PM
yeah no that does not work
E
Eakam
•
9/30/22, 11:16 PM
Oh
, that
's not what I meant
R
Revan
this is what i did but its not working.
E
Eakam
•
9/30/22, 11:16 PM
The thing with using cin
.ignore
(
'
/
'
) first is that it will read and discard everything until it finds the
'
/
'
R
Revan
OP
•
9/30/22, 11:17 PM
So I have to use cin
.ignore
(
‘
\n
’
) in the same line to ignore the end of the line
?
E
Eakam
•
9/30/22, 11:18 PM
ignore does not ignore one thing
. It ignores everything until it find what you specify
R
Revan
OP
•
9/30/22, 11:19 PM
So I don
’t want it to ignore the first two numbers before
/
E
Eakam
•
9/30/22, 11:20 PM
Yea
, you want to read those number before you ignore the
'
/
'
R
Revan
OP
•
9/30/22, 11:21 PM
cin
>
>variable1
>
>cin
.ignore
(
‘
/
‘
)
>
>variable2
?
E
Eakam
•
9/30/22, 11:28 PM
I am not sure if that syntax will work but that is what you want to do
E
Eakam
•
9/30/22, 11:36 PM
Actually that might not work since the first argument to ignore
(
) is supposed to be the number of characters you want to ignore
R
Revan
OP
•
9/30/22, 11:50 PM
R
Revan
OP
•
9/30/22, 11:50 PM
this works for me but the assignment says i need to do this all in one line
R
Revan
OP
•
9/30/22, 11:50 PM
is there a short form for this
?
E
Eakam
•
9/30/22, 11:57 PM
Haven
't done c
+
+ in a while but you can
't chain these
?
R
Revan
OP
•
9/30/22, 11:57 PM
my c
+
+ knowledge is about 1 month
. whats a chain
?
R
Revan
OP
•
9/30/22, 11:57 PM
unless chaining is c program thing as well then its my fault
E
Eakam
•
9/30/22, 11:58 PM
Like this cin
>
> tempExpMon
>
> cin
.ignore
(
.
.
.rest of code
E
Eakam
•
9/30/22, 11:58 PM
Same way you have put the ignore and tempExpYear on one line
E
Eakam
•
9/30/22, 11:59 PM
Though if that doesn
't work
, you could read that character into something else I suppose
R
Revan
OP
•
9/30/22, 11:59 PM
R
Revan
OP
•
9/30/22, 11:59 PM
yeah i get this when i try that
E
Eakam
•
10/1/22, 12:00 AM
Ah
, so it isn
't possible to do that
. Unfortunate
R
Revan
OP
•
10/1/22, 12:00 AM
oh well it works the other way so its all good
R
Revan
OP
•
10/1/22, 12:00 AM
thanks for all the help
Similar Threads
how do you check if cin fails?
CP-SPC
Computer Programming - Seneca Polytechnic College / ask-a-question
4y ago
Transferring to a different school
CP-SPC
Computer Programming - Seneca Polytechnic College / ask-a-question
3y ago
How do I make a complaint about a professor?
CP-SPC
Computer Programming - Seneca Polytechnic College / ask-a-question
3y ago
how do i get appxmanifest
CP-SPC
Computer Programming - Seneca Polytechnic College / ask-a-question
2y ago