Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take input of two data without using space or enter

Tags:

c++

input

In C it is very simple scanf("%d : %d",&a,&b) say input 5:10 . So here a=5 and b=10. (:)Just split them into two as a separate integer. How can we do in C++ without using space or enter between two input

int a,b;
cin>>a>>b; // how we take input two integer taking as 5:10
cout<<a<<b; // a=5 and b=10
like image 615
Sofi Ullah Saikat Avatar asked May 08 '16 08:05

Sofi Ullah Saikat


People also ask

What does input () split () do?

It takes a string as input and splits it wherever it encounters a “separator” (a character that acts as a marker for the split). The output is a list of strings, where the elements are the individual parts of the input string after the splits. By default, split() assumes the separator to be whitespace (“ ”).

How do you separate two inputs by space?

Using split() method : This function helps in getting a multiple inputs from user. It breaks the given input by the specified separator. If a separator is not provided then any white space is a separator. Generally, user use a split() method to split a Python string but one can use it in taking multiple input.

How do you take two inputs in one line Python?

Using split() method This function helps in getting multiple inputs from users. It breaks the given input by the specified separator. If a separator is not provided then any white space is a separator. Generally, users use a split() method to split a Python string but one can use it for taking multiple inputs.

How do you take user input separated by space in Python?

Use an input() function to accept the list elements from a user in the format of a string separated by space. Next, use a split() function to split an input string by space. The split() method splits a string into a list.


1 Answers

int main()
{
    int a, b;
    char c;
    std::cin >> a // Read first number,
             >> c // oh, there is a character I do not need
             >> b; // and read second
}

Or if you do not like having to declare that spare variable, this also works.

    std::cin >> a;
    std::cin.ignore(1);
    std::cin >> b;
like image 199
Zereges Avatar answered Oct 04 '22 04:10

Zereges