1

i have to open and read a file with c++. I'm doing like this:

#include<iostream>
using namespace std;
int main()

{

ifstream fin ("P01-05 tensione di vapore di riferimento fino 180°C.dat");

if (!fin)
{
    cerr << "\nErrore: non si puo aprire il file.\n" << endl;
    exit(1);
}

string line;

 while (getline(fin,line))
....

but i want to know if there is an alternative way to read a file until the EOF without using a loop like in this case.

Thank you

  • You could ask the operating system what the size of the file is and read the whole thing in one go... but why do you want to avoid loops? – CompuChip Nov 10 '15 at 16:23
  • I ran into this question about [reading a file line by line without using a loop](http://stackoverflow.com/questions/15839407/reading-file-line-by-line-without-using-for-while-loop). You can check it out and see if that helps with your implementation. – don Nov 10 '15 at 16:27
  • ok thank you i'll take a look! – Paolo Orsatti Nov 10 '15 at 17:03

0 Answers0