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
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 (“ ”).
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With