C
Christopher Reeve
Hi, I wonder if anyone could help me. I am moving accross from C to
C++ and am writing a program that reads and writes data into a file. I
am aware of the old C ways of doing it but am trying to use the C++
functions which don't seem to be working propperly.
I need to open the file for reading and writing because I want to
search for a possition in a file called settings.dat and then write a
number after a certain chatacter. However when I use
examplefile.get(buffer,100); or examplefile.getline(buffer,100), in
addition to reading to the file it also modifies it by inserting the
first three characters of what ot read back into the place it started
reading from. Does anyone know why this might be happening or how I
can get arround this? I am using Dev-C++.
I'll give this test program as an example, it requires any old file
called settings.dat
================================================
#include <iostream>
#include <fstream>
#define FSETTINGS "settings.dat"
using namespace std;
int main () {
char buffer[256];
//fstream examplefile;
fstream examplefile (FSETTINGS);
//examplefile.seekg(9,ios::cur);
examplefile.get (buffer,100);
cout << buffer << endl;
system ("PAUSE");
return 0;
}
==============================================================
C++ and am writing a program that reads and writes data into a file. I
am aware of the old C ways of doing it but am trying to use the C++
functions which don't seem to be working propperly.
I need to open the file for reading and writing because I want to
search for a possition in a file called settings.dat and then write a
number after a certain chatacter. However when I use
examplefile.get(buffer,100); or examplefile.getline(buffer,100), in
addition to reading to the file it also modifies it by inserting the
first three characters of what ot read back into the place it started
reading from. Does anyone know why this might be happening or how I
can get arround this? I am using Dev-C++.
I'll give this test program as an example, it requires any old file
called settings.dat
================================================
#include <iostream>
#include <fstream>
#define FSETTINGS "settings.dat"
using namespace std;
int main () {
char buffer[256];
//fstream examplefile;
fstream examplefile (FSETTINGS);
//examplefile.seekg(9,ios::cur);
examplefile.get (buffer,100);
cout << buffer << endl;
system ("PAUSE");
return 0;
}
==============================================================