-
handling user input
I am trying to figure out how to receive and handle user input in c++?
If i want the user to enter input like this, line by line
how can I take each of these values and store them..so i can work with them.?
(ie. so i can place them into a function that takes (int a, int b))
I want to start practicing with online judge but I cant quite get the hold of taking user input
-
Study about std::cin you will get to know
and for storing data read about data types and variables
and about displaying data read about std::cout
-
Declare some variables of the proper type, and "cin" into them.
-
even if their on the same line?
the input will be not be inputed by me, it will be inputted LINE BY LINE by an online evaluator.
so my code must be able to understand when i type in "1 10" enter "100 200"
Sample Input
1 10
100 200
201 210
900 1000
I will post my initial attempt :)
Code:
int main()
{
int nums[8];
for(int i =0 ;i < 8; ++i)
{
cin>>nums[i];
}
O wait, it worked...I am guessing that the space in the between the numbers doesn't even matter.
-
Correct. When getting numbers from the input, whitespace is ignored.