A more efficient way for file I/O in C++?
Moderator: Coders of Rage
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
A more efficient way for file I/O in C++?
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?
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: A more efficient way for file I/O in C++?
Yeah, of course ifstream can read into multidimensional arrays:
Code: Select all
ifstream file(filename);
file >> variable[x][y];
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: A more efficient way for file I/O in C++?
You can even be like awesome and
or
Code: Select all
vector <int> nums;
int num;
file >> num;
while (file) {
nums.push_back(num);
file >> num;
}
Code: Select all
int array[20zillion];
for (int i = 0; file && i != 20zillion; ++i) { //lolololol
file >> array[i];
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Re: A more efficient way for file I/O in C++?
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.)
i think C++ is making developers lazy and ultimatly stupid. (no offence to anyone.)
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"