M
M
Mushrumov2019-03-29 05:39:06
C++ / C#
Mushrumov, 2019-03-29 05:39:06

Read file as stream and write to 2D array?

There is a source text file input.txt, you need to read the entire contents of the file as a stream and throw it into a two-dimensional array. I tried to do this but I only read the first line

char line [5][20];
int count=0;
fstream fIn;
fIn.open("input.txt",ios::in);

while(fIn.getline(line[count],20))
count++;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nirvimel, 2017-01-07
@nirvimel

A reference to an array element linethat is of type Line.

K
Konstantin Stepanov, 2017-01-07
@koronabora

+1 to nirvimel , but it's more common to see references in method and function signatures. And here, roughly speaking, this code makes it easier to read and allows you to write just l instead of lines[n%N] .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question