Thread: file io ?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    file io ?

    When reading in strings from a file is it alright if the strings are on separate lines? like if i was doing:


    string str1, str2, str3;

    ifstream file("foobar.txt");

    file >> str1 >> str2 >> str3;
    cout << str1 << str2 << str3

    and foobar.txt reads

    stringone stringtwo (a new line)
    stringthree

    would there be any problem due to the newline?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    As long as the strings don't have spaces in the middle of them(in your file) it would be ok.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    I'm not sure what Zen means by spaces in the middle of your strings. That statement is confusing.

    The ifstream object uses a get pointer to position the file pointer at the next input location in your file. So, when processing your file sequentially, the get pointer is automatically advanced to the next, sequential data location. White space is ignored, to include '\n'.

    hth,

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    ok thanks

    thanks, it did work.

    and i think he meant that if one of my strings was

    "str ing1" it would read in "str" and "ing1" as separate streams.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 10:18 AM