Thread: Spaces in files

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    Spaces in files

    Ok i've got my file working for input, but I can't get it to except spaces,

    Code:
    ofstream outfile("*file name*", ios::out);
    	outfile << song[arraynumber].artist;
    	outfile << song[arraynumber].title;
    	outfile << song[arraynumber].mediafile;
    	outfile << song[arraynumber].genre;
    	outfile << song[arraynumber].duration;
    outfile.close( );
    This works fine but when i open up my text document it would have something like,

    AC\DCback in blackmp3rock345
    Is there something I can add so that each one starts on a new line so they can be read from the file seperately, like they were stored?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You can output a space to add a space between items, or a newline to add a new line. The space character is just a space between single quotes: ' ', and the newline character is '\n'.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    Thanks got it working now. Didn't realise that would work for a file.
    Last edited by ManiacBR; 11-22-2006 at 04:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing 3 spaces to tabs
    By dnguyen1022 in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 12:51 AM
  2. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  3. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  4. Handling spaces in command line arguments
    By starkhorn in forum C++ Programming
    Replies: 7
    Last Post: 11-16-2004, 02:42 PM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM