Thread: File IO / help please

  1. #1

    File IO / help please

    I am making a little program that encodes text files, but I have a small problem.

    The text file has this text: test line
    My program output text: testlline
    (there is no encodeing going on yet)

    It replaces the spaces with the char infront of it.

    here is my code:

    // Read Char //
    cfile >> char_buffer;

    // Encode Char //
    int_buffer = int(char_buffer);

    // Write Char
    char_out = char(int_buffer);

    cfile << char_out;


    I am trying to leave the spaces as spaces, or even better, encode them too. Is my program skipping the spaces because of the code: cfile >> char_buffer; ?? if so, what way can I input text from a file?

    thanks alot!

  2. #2
    Registered User
    Join Date
    Jan 2002
    you might want to use the function member function 'get(char *, int)', (or since you seem to be inputting a single character at a time, 'get(char &ch)') to read in data.

    // Read Char // 
    // Encode Char // 
    int_buffer = int(char_buffer);  //casting isnt necessary here, char_buffer += -1, or simply char_buffer-- will suffice
    // Write Char 
    char_out = char(int_buffer); 
    cfile << char_buffer;
    might I suggest you read in a few more char's than just one at a time, like say 1000 (or more, depending on file size), and encoding the whole buffer, it will go much quicker

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, 04: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, 09:18 AM
Website Security Test