Taking a single dimension array from a user
Apr 19, 2018 at 10:36pm UTC
I am trying to take an array size from a user, take the array elements from the user, and then print it, but for some reason, taking the inputs from the user in cin>>A[i]; (//PROBLEM after it in code) returns cannot bind stdistream to stdbasicstream. What am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <iostream>
using namespace std;
int main()
{
int ** A;
int s;
cout << "Enter number of rows: " ;
cin >> s;
A = new int *[s];
for (int i=0;i<s;i++)
{
A[i]=new int [s];
cout<< "Enter element in row " <<(i+1)<<":" ;
cin>>A[i]; //PROBLEM
}
cout<< "The matrix you have input is:\n" ;
for (int i=0;i<s;i++)
{
cout << A[i] << " " ;
}
for (int i=0;i<s;i++)
delete [] A[i];
}
Apr 19, 2018 at 11:52pm UTC
Hello FireyBolt,
Your topic says 1D array yet your code is creating a 2D array, which is it that you want to work with?
It makes a difference on how you will need to do your code.
Andy
Apr 20, 2018 at 1:27am UTC
Delete/comment out line 14. You are creating a 2 dimension array from the single dimension array you create in line 10.
Topic archived. No new replies allowed.