Reading data from a file

Hello!

So I have a file created named "inputs.dat", and inside that file, I have coordinates entered exactly like this:
4 1
1 4
10 12
1.1 4.5
3 10.3
10 7

What I'm trying to do is write a code that would read in from that file I created, and store those numbers in parallel arrays. The code has to be able to read in a file size up to 1000 lines and it has to keep reading until the end of the file.

This is what I started with:

1
2
3
4
5
6
7
8
cont int FILE_SIZE = 1000;
ifstream inFile;
inFile.open("inputs.dat");

if(!inFile)
{
   cout << "Error opening file" << endl;
}
Last edited on
1
2
3
4
5
6
for(
   int K=0;
   K<1000 and inFile>>x[K]>>y[K];
   ++K
)
   ;



edit: fixed typo
Last edited on
What do you mean by "and"? Like write in the code "&&"?
Last edited on
Hi,

and is a keyword, means the same as &&.

There are a bunch of them:

http://en.cppreference.com/w/cpp/language/operator_alternative
Topic archived. No new replies allowed.