Thread: saving a CString to binary file with trailing spaces

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    8

    saving a CString to binary file with trailing spaces

    Heres what i want to happen except i want it to happen with a CString instead of a char []:

    Code:
    char name[10] = "Bob      ";
    
    ofstream fout(filename, ios::binary);
    
    fout.write(name, sizeof(name));
    
    fout.close();
    the output has 'Bob .' (with the trailing spaces).
    when i try this with CString it give me 'Bob.......' (with null's instead of spaces)
    I know that CString doesn't have the trailing spaces and is only 'Bob'.

    How do i either tell CString to be 10 spaces no matter what, or copy CString to Char[10] and have the spaces, or some other way of fixing it ;-)
    Last edited by nineofhearts; 01-02-2006 at 04:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM