read from file into 2d array

Write your question here.
I try to read digits from file txt. ,but I can not open it.Where I made a mistake?

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
29
30
31
32
33
34
35
36
37
38
39
40
  P#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	int i,j,n,m;
	cout<<"enter n";
	cin>>n;
	cout<<"enter m";
	cin>>m;
	double**a;
	a=new double*[n];
	for(i=0;i<n;i++)
	a[i]=new double[m];
	ifstream input("z72.txt",ios::in);
	if(!input){
		cout<<"file not open"<<endl;
		return 1;
		
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			input>>a[i][j];
	}
	input.close();
	cout<<"matrica"<<endl;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			cout<<a[i][j]<<" ";
		cout<<endl;
	}
	
    for (int i = 0; i < n; i++) 
     delete[] a[i];
     delete[] a;
	
	return 0;
}ut the code you need help with here.
Line 15 should be like this:
1
2
ifstream input;
input.open("z72.txt",ios::in);
the program is fine.
In your if statement
if(!input)
it should look something like this
if(!input.is_open())
That member function checks if the file is open or not.
@ newbiee999, HatchetMan302, and OP, the program is just fine. fault must be in other place(s).
Thanks , but an error here that I do not have to specify the size of the array.
How to read the file without knowing its size?
use std::vector
Topic archived. No new replies allowed.