Problems with Cin

Im pretty new to c++, and am really only using cin and cout so far, but im creating a program for a math class that can quickly multiply matrices together. I have created the whole thing but have one problem.
when a user enters the two matrices they have to enter it like this:
3
4
5
6

Is there anyway to set up cin so that I can have users input numbers like this?
3 4
5 6

Where two inputs are found on one line.

Any help would be very much appreciated.
Hello!

Here is my probe code:

1
2
3
4
5
6
7
8
9
10
11
include <iostream>
using namespace std;

int main()
{
	int a,b;
	cin >> a >>b;
	cout << endl;
	cout << "a: " << a << "b: " << b;
	return 0;
}


If cin / >> operator meet with space seperated data then the data will be read separate. Just you should use cin >> a >> b >> c >> d

Of course you should check the reading with if (cin.good()){} statement.
Last edited on
Topic archived. No new replies allowed.