0

I want to use cin>> in c++ to write the values into a bi-dimensional array on the same line..I don't know English very well but I'll show you an example:

So I have an array and I want to write in it 24 numbers(4 rows, 6 colons) and I want to input all the 6 numbers on the same line not like cin>> usually does like jumping on a new line. I got this so far :

int m,n,i,j,a[50][50];
    cout<<"Input the number of rows : ";
    cin>>n;
    cout<<"Input the number of columns : ";
    cin>>m;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cout<<"Introduceti a["<<i+1<<"]["<<j+1<<"] : ";
            cin>>a[i][j];
        }
    }

But this does the usual jump on a new line every time I input something.

Is that possible?..Thank you! :)

Thank you! :)

Daniel Bejan
  • 1,468
  • 1
  • 15
  • 39
  • You can't do this with cin alone; see some of the answers here: http://stackoverflow.com/questions/15209370/how-do-i-input-variables-using-cin-without-creating-a-new-line – Riot Dec 01 '13 at 21:21
  • 1
    Why don't use use ```std::getline()``` to get the entire line, then tokenize it, and use the tokens. – turnt Dec 01 '13 at 21:21

1 Answers1

0

Your issue is with cin >> value which usually requires the User to press ENTER to cause the processing of the input.

The ENTER is echoed back, causing a new blank line.

As others have said, you could use std::getline() to read a lot of data before the ENTER is pressed.

The question is, is a blank line echoed really worth the effort to avoid?

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154