grrrrr...somthins not workin

Started by
4 comments, last by slightlywhacked 23 years, 5 months ago
AAARRRGGGHHHH plz help me when i do this ifstream infile; #include #include #include #include #include char sp1[50]; main() { infile.open("trucks.dat",ios::in); infile.get(sp1,50); infile.ignore(80, ''\n''); infile.close() return(0); } sp1 reads blank...just a space.. and yes the dat file has stuff there for it to read.. and it is in the right spot..and yes trucks.dat is there.... whats goin on?? ive been at this for hours and im pullin my hair out (the project that im doing is a lot larger than this, but I just put the exsample into a smalller chunk so its easier to read) help me plz thanks in advance
BAHcows go moomoos go cow
Advertisement
in the above code the headers got excluded cause i guess those greter than and less than signs are considered for html tags in this thing...
but the includes are

fstream.h
iostrea.h
stdlib.h
string.h
BAHcows go moomoos go cow
How do you even know whats in sp1? Are you using debug mode and stepping through? Or do you print the value and you just left out that code. BTW, ios::in is not needed as a second parameter in infile.open() . Its default.

=======================================
Better to reign in hell than serve in heaven.
John Milton, Paradise Lost
yes.. later I print it out onto trucks.dat again.. and its just a blank space...but further down, there is still stuff in the document, proving that i AM writing to it... its just the stuff I try to get off files that are screwing up

Edited by - slightlywhacked on November 4, 2000 1:45:27 AM
BAHcows go moomoos go cow
hmm, i don''t know if this is the problem, but you might want to open the file as ios::binary, i.e.:

infile.open("trucks.dat",ios::in|ios::binary);

maybe it thinks it''s reading in chars, and stops at a space or a ''\n'' or ''\0'' or something... or is it getc() that does that?
i dunno.. i''m tired.. sorry if i''m of no help

------------------------
IUnknown *pUnkOuter

"Try the best you can
try the best you can
the best you can is good enough"
--Radiohead
------------------------IUnknown *pUnkOuter"Try the best you cantry the best you canthe best you can is good enough" --Radiohead
The code as you've given it should:

o Open the file "trucks.dat" as a text-file for input only
o Get the first line (ending in '\n') or 50 characters of the file.
o Ignore the next line of the file (why?, when you're about to: )
o Close the file

I'd stick some debugging code in there, to display the file-position before and after getting the string (use infile.tellg() to get the current 'get' position). You should also check that you've successfully opened the file (infile.is_open())! If the file isn't opened properly it could be in a different directory, or it may be open for writing somewhere else.

Dave

Edited by - Heraldin on November 4, 2000 12:09:50 PM

This topic is closed to new replies.

Advertisement