//Save FILE *stream = fopen( fnbuf, "w+" ); //MSDN : //"w+" Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed //int i = Antal Strenge //while (i) { //char *p = &Strneg nummer i fputs(p, stream); } fclose( stream );
tomasolsen >> kan det virkelig passe der ikke er nogen "r", "w", "a" eller lignende parameter i file.open kaldet når man åbner en fil i c++? Om det er read eller write gør en masse forskel for hvilke rettigheder og aflåsninger der skal requestes i operativsystemet.
basic_filebuf *open(const char *s, ios_base::openmode mode); The member function endeavors to open the file with file name s, by calling fopen(s, strmode). Here strmode is determined from mode & ~(ate & | binary):
ios_base::in becomes "r" (open existing file for reading). ios_base::out or ios_base::out | ios_base::trunc becomes "w" (truncate existing file or create for writing). ios_base::out | app becomes "a" (open existing file for appending all writes). ios_base::in | ios_base::out becomes "r+" (open existing file for reading and writing). ios_base::in | ios_base::out | ios_base::trunc becomes "w+" (truncate existing file or create for reading and writing). ios_base::in | ios_base::out | ios_base::app becomes "a+" (open existing file for reading and for appending all writes).
I eksemplet jeg skrev, skal man huske at lægge mærke til at "ifstream" bliver brugt ved indlæsning, "ofstream" til udskrivning... =)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.