About File I/O

This is a discussion on About File I/O within the C++ Programming forums, part of the General Programming Boards category; Is there a way to use the overloaded get function as follows, ifstream infile(whatever); char* buffer; infile.get(buffer, 100, '1'); but ...

  1. #1
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113

    About File I/O

    Is there a way to use the overloaded get function as follows,


    ifstream infile(whatever);
    char* buffer;

    infile.get(buffer, 100, '1');


    but to have more than one delim character? i.e. to stop reading upon finding any of three or four variables? i might guess the following..

    infile.get(buffer, 100, '1' && '2' && '3');

    or something similar, but i dont know? anyone can point me to someplace I can find out?

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    not sure if it will work but try using | instead of the &&

  3. #3
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    Another new problem:

    okay so here I have my program.
    outside the forever loop, I defined all my variables including a string to store the name of which file we are currently working on.
    inside the forever loop, it opens a datafile, reads the contents to the user, and reads the names of 1-9 other files, out of which the user can choose. After reading all this from the current datafile, it moves into the user choice section, where user chooses 1-9, quit, menu, etc, some of which will of course break out of the forever loop.
    Now, when the user chooses anything from 1-9, a switch checks if that particular choice is available in this file, and if so, changes the string (defined outside the loop) to contain the name of the new file, and closes the current file.
    then the loop starts over.
    HOWEVER:
    everytime the loop starts over, and the program gets to the point where it should load the new file, it generates an invalid page fault.

    Any ideas on what might be causing this? I'm guessing you'll want the code posted right? I will put it up as soon as I can..

  4. #4
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    err... umm.. eh.. now i got a really good one.. dont laf..
    how do i post attachments?

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    in the reply screen beneath where you type your reply should be an options section and bellow it is attach file

  6. #6
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113

    okay i figgered it out....

    I wasnt logged in b4 so it didnt show up thx man
    anyway heres the src code for my project (note btw that it is not complete)
    Attached Files Attached Files
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

  7. #7
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    doh i forogt to include the data files
    they're just test versions but heres a couple to let the thing run (at least as far as it does run anyway)
    Attached Files Attached Files
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

  8. #8
    Geek. Cobras2's Avatar
    Join Date
    Mar 2002
    Location
    near Westlock, and hour north of Edmonton, Alberta, Canada
    Posts
    113
    I absolutely swear this post was not here five minutes ago.
    I know it wasn't.
    Maybe I'm going insane but it was definately *not* here when I looked for it.
    maybe it has something to do with me logging in to write that last post? .... i think ill have to make sure to be logged in from now on cause strange things keep happening when im not ..
    James G. Flewelling
    Rgistered Linux User #327359
    Athabasca University Student (BSc. CIS)

    http://catb.org/~esr/faqs/smart-questions.html
    http://catb.org/jargon/

    http://www.ebb.org/ungeek
    ---GEEK CODE---
    Version: 3.12
    GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
    E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
    tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
    ----/GEEK CODE----
    upd: 2005-02-11

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 04:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21