Thread: File i/o problem

  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
    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.

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, 04: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, 12: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