File i/o problem

This is a discussion on File i/o problem within the C++ Programming forums, part of the General Programming Boards category; That example's short n' cute, I like that. *Thanks for the suggestions, pointers, et cetera. Trust me, I'm not looking ...

  1. #16
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    That example's short n' cute, I like that.

    *Thanks for the suggestions, pointers, et cetera. Trust me, I'm not looking to create code any more complex than it need be, just doing my best to understand it all.

  2. #17
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Since we're on this subject of getline (grabbin' words), etc., if you have a file buffered as a string file (not char, but a 'string myfile'), is there a method of applying getline to read the string or perhaps another method that I'm unfamilar with?

    ie.
    Code:
     getline(myfile,anotherstring,'\n')
    won't work since myfile isn't istream but the stored contents of the file. I need to process the data a 2nd time before output to a file, though I can't figure out how to do that.
    Last edited by Oldman47; 01-01-2007 at 08:37 AM.

  3. #18
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Use a stringstream
    Code:
    string myfile; // holds the total contents of a textfile
    stringstream str(myfile);
    while (  getline( str, anotherstring /*, '\n' */ ) ) {  // '\n' is default 
        // process anotherstring
    }
    Kurt

  4. #19
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Ah! So that's how one does that. Thanks. I was scratchin' my head for several hours over this.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  2. File I/O problem
    By Onions in forum C++ Programming
    Replies: 41
    Last Post: 02-24-2006, 04:32 PM
  3. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 01:14 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM

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