* DEC Alpha C++ problem
@ 1995-08-28 4:00 Jeffrey T. Ehrhart
1995-08-29 4:00 ` Peter Mayne
0 siblings, 1 reply; 2+ messages in thread
From: Jeffrey T. Ehrhart @ 1995-08-28 4:00 UTC (permalink / raw)
I am having a problem with the DEC Alpha C++ fstream
functions. My code looks like this:
xfile.open("test.txt", ios::in);
char delimiter[6];
xfile.getline(delimiter, 7); // Read first 6 characters
xfile.seekg(0); // Reset to file beginning
xfile.sync(); // Sync file and fstream buffer
The problem is that the next getline invocation does
not read from the beginning of the file like I wanted
it to. It appears as if either the seekg or sync
functions did not work as I expected. Do I need to
do something different to move the file pointer back
to the beginning of the file? Is it a problem with the
DEC C++ library functions? HELP !!!
This code works as expected under Visual C++ on
the PC and the CC compiler on a SUN.
Any help would be appreciated...thanks,
Jeff Ehrhart
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: DEC Alpha C++ problem
1995-08-28 4:00 DEC Alpha C++ problem Jeffrey T. Ehrhart
@ 1995-08-29 4:00 ` Peter Mayne
0 siblings, 0 replies; 2+ messages in thread
From: Peter Mayne @ 1995-08-29 4:00 UTC (permalink / raw)
In article <41tefq$68p@fermat.mayo.edu>
ehrhart.jeffrey@mayo.edu (Jeffrey T. Ehrhart) wrote:
> I am having a problem with the DEC Alpha C++ fstream
> functions. My code looks like this:
>
> xfile.open("test.txt", ios::in);
> char delimiter[6];
> xfile.getline(delimiter, 7); // Read first 6 characters
> xfile.seekg(0); // Reset to file beginning
> xfile.sync(); // Sync file and fstream buffer
>
> The problem is that the next getline invocation does
> not read from the beginning of the file like I wanted
> it to. It appears as if either the seekg or sync
> functions did not work as I expected. Do I need to
> do something different to move the file pointer back
> to the beginning of the file? Is it a problem with the
> DEC C++ library functions? HELP !!!
>
> This code works as expected under Visual C++ on
> the PC and the CC compiler on a SUN.
Caution: I know nothing, I'm just reading the manual.
The VC++ help for getline says:
Extracts characters from the stream until either the delimiter delim
is found, the limit nCount-1 is reached, or end of file is reached.
The characters are stored in the specified array followed by a null
terminator. If the delimiter is found, it is extracted but not stored.
Therefore, you're reading 6 characters, but storing 7 characters (your
6 plus a '\0') in the 6 character array. Maybe the '\0' is overwriting
something it shouldn't? The fact that it works elsewhere may be luck.
Or, you could try tellg before the getline, or cast 0 to streampos?
PJDM
--
Peter Mayne
Digital Equipment Corporation (Australia)
Canberra, ACT
----
These are my opinions, and have nothing to do with Digital.
The truth is out there, but not necessarily in here.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1995-08-29 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-08-28 4:00 DEC Alpha C++ problem Jeffrey T. Ehrhart
1995-08-29 4:00 ` Peter Mayne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox