Thread: iostream manipulators

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490

    iostream manipulators

    let's say i have a data file i want to write:
    Code:
    float gpa=3.45654;
    int cost=45430;
    string name;
    name = "two words"
    ofstream out("out.file");
    out << gpa << cost << name;
    out.close();
    
    /* .... */
    
    ifstream in("out.file");
    in >> gpa >> cost >> name;
    in.close();
    most of you can see the problem here: name has a space in it. what i want to do is seperate each field with a comma (or some other distinct marker). is there a manipulator that can automatically end everything with a character of my choice?

    //edit: for instance:
    out << gpa << cost << name;
    should output
    3.45654,45430,two words

    and input should act like this:
    in >> gpa >> cost >> name;
    it should take a float, throw away the comma, get the integer, throw away the comma, then get the whole string, regardless of spaces, but only until it hits a comma (or the end of the string).

    theoretically, anyway. i don't know if this is possible even with changing the iostream and/or the string classes
    Last edited by ygfperson; 07-18-2002 at 01:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drieving from iostream
    By Thantos in forum C++ Programming
    Replies: 8
    Last Post: 06-23-2004, 04:57 PM
  2. iostream & hex?
    By dmlx90 in forum C++ Programming
    Replies: 0
    Last Post: 05-22-2002, 11:51 PM
  3. DJGPP Doesn't include IOSTREAM!!!!!!!!!!!
    By Frenchfry164 in forum Game Programming
    Replies: 12
    Last Post: 10-27-2001, 12:27 PM
  4. << in iostream
    By badman in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2001, 10:19 PM
  5. Is there a C iostream?
    By Khisanth in forum C Programming
    Replies: 1
    Last Post: 09-05-2001, 12:34 AM