Advertisement

How do you load files

Started by February 23, 2001 02:37 PM
3 comments, last by caffeineaddict 23 years, 11 months ago
Ok, I am writing a program that I need to be able to save the values so you don''t have to type them in every time, this is a dos program and I know how to save the values to a file i just don''t know how to load them, any help would be appreciated.
What method are you using saving them? I guess knowing that will make it easier to give you an answer.
Advertisement
#include

int main(){
std::ofstream filevariable("test.dat", std::ios::app);
filevariable << "This text is appending to the file";
}


#include

int main(){
std::ofstream filevariable("test.dat");
filevariable << "This text is overwritting the file (i think)";
}

let me know if i''m doing anything wrong and if you can help, thanks
#include #include #include int main(){    std::ofstream ofile( "file.sav" );    std::string temp( "hi there" );    ofile << temp << std::endl;    ofile.close();    temp = "";    std::ifstream ifile( "file.sav" );	if( !ifile.is_open() )		return( 0 );    std::getline( ifile, temp );	ifile.close();    std::cout << temp << std::endl;    return( 0 );} 
Iostreams aren''t as fast as you could wish, so if you don''t need all their extra functionality you''re probably better off using the standard C function set. Iostreams are also C++ and thus they come with an portability and reusable code problem, fopen et al don''t. Least but not last fopen/fread/etc are easier to deal with in the beginning because you don''t have to care about classes, namespaces and fancy overloaded operators.

  #include <stdio.h>...FILE *f;MY_STRUCT my_struct;/* For writing */f = fopen("abc.def", "wb");my_struct.foo = 2;...fwrite(&my_struct, sizeof(MY_STRUCT), 1, f);fclose(f);/* And for reading */f = fopen("abc.def", "rb");fread(&my_struct, sizeof(MY_STRUCT), 1, f);fclose(f);...  



"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album

This topic is closed to new replies.

Advertisement