Page 1 of 1

A more efficient way for file I/O in C++?

Posted: Tue Nov 25, 2008 11:23 pm
by davidthefat
I think fstream and ofstream and ifsteam is decent but what if you have to load more that a dozen line of text like a journal or something. for example, a file with data of the weights i used. what im asking is that can the functions be used with multidimensional arrays?

Re: A more efficient way for file I/O in C++?

Posted: Tue Nov 25, 2008 11:48 pm
by Falco Girgis
Yeah, of course ifstream can read into multidimensional arrays:

Code: Select all

ifstream file(filename);
file >> variable[x][y];

Re: A more efficient way for file I/O in C++?

Posted: Fri Nov 28, 2008 12:02 am
by MarauderIIC
You can even be like awesome and

Code: Select all

vector <int> nums;
int num;
file >> num;
while (file) {
    nums.push_back(num);
    file >> num;
}
or

Code: Select all

int array[20zillion];
for (int i = 0; file && i != 20zillion; ++i) { //lolololol
    file >> array[i];
}

Re: A more efficient way for file I/O in C++?

Posted: Fri Nov 28, 2008 11:16 am
by avansc
people dont rely on plain text, make binary files and just read entire stuctures/classes at a time, alot faster than processing each line or what not.
i think C++ is making developers lazy and ultimatly stupid. (no offence to anyone.)