Thread: white spaces ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    white spaces ...

    I'm doing a program where I send a string to a file, and I want to read it back, but when I do that, the white spaces only come up as nothings .... all the words are cascaded together , for example

    write to the file: "This is a test!"
    I get from it: "Thisisatest!"

    anyone know how to overcome this??

    I obviously tried to use an if statement which tested for white spaces. Also, the file itself has the spaces in it, so why doesn't the reading function include them?
    Last edited by eagles; 01-13-2006 at 07:18 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    use getline() to read a complete line including ws.
    Kurt

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    Quote Originally Posted by ZuK
    use getline() to read a complete line including ws.
    Kurt
    took me a while to realise what ws is ... cheers!!

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    hmmm, how does the getline() function work?? like what parameters are inthe brackets??

  5. #5
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by twomers
    hmmm, how does the getline() function work?? like what parameters are inthe brackets??
    Guess what you need is a reference. This one was helpful for me
    http://www.cppreference.com/
    Kurt

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    hang on, does that work for file IO?

  7. #7
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Shure. Works wit every input stream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading white spaces? oh and scanf_s
    By RobotGymnast in forum C++ Programming
    Replies: 7
    Last Post: 11-01-2008, 05:32 AM
  2. Replies: 1
    Last Post: 03-08-2005, 12:02 PM
  3. white spaces
    By Jules in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2004, 02:55 PM
  4. string input...with white spaces?
    By Pureghetto in forum C Programming
    Replies: 6
    Last Post: 03-10-2003, 01:52 PM
  5. Reading in text file into an array, white spaces...
    By error in forum C++ Programming
    Replies: 12
    Last Post: 01-14-2003, 09:39 AM