Taking a single dimension array from a user

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];
}
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
closed account (E0p9LyTq)
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.