Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to read data from file to plastic array data in C++
How to read data from file to plastic array data in C++
# contains "stdafx.h"

# include & ltiostream & gt

# include & ltfstream & gt

# include & ltcstdlib & gt

Use namespace std

int main()

{

Character file name [20];

int a[3][3]; //Store integers

CIN & gt; & gt file name;

Ifstream ifile (file name, IOs _ base:: in);

The If(ifile) // file has been successfully opened.

{

for(int I = 0; I<8; I++) // Read eight integers.

ifile & gt& gta[I/3][I % 3];

}

other

{

Cout & lt& lt "Failed to open file"<& ltendl

Exit (1);

}

//You can output an [i][j] here to verify whether it is read correctly.

for(int I = 0; I<8; i++)

cout & lt& lta[I/3][I % 3]& lt; & lt" ";

cout & lt& ltendl

Returns 0;

}