Results 1 to 5 of 5

Thread: Convert Text File To Binary

  1. #1
    Join Date
    Dec 2008
    Posts
    33

    Convert Text File To Binary

    hi,

    i have small problem in C + + there.

    I have a. txt all that is simple and readable format ascii in notepad and I would copy the contents to a binary file (to be called up to win).

    I use the following functions:
    fread and fwrite for access binary ansi_c fgets, fputs, fgetc, fputc access to text


    To read it well be the same thing but in the opposite direction to regenerate the txt file from the binary.

    a little help or track?

    thank you

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Convert Text File To Binary

    hi,
    use std:: ostream, std:: IStream with good flags.

  3. #3
    Join Date
    Dec 2008
    Posts
    33

    Re: Convert Text File To Binary

    I am based on the examples of functions:

    Code:
    • int length; char * buffer; ifstream infile ( "D: \ \ test.txt", ifstream:: in); ofstream outfile ( "D: \ \ test.bin", ofstream:: binary); / / Get length of file: infile.seekg (0, ifstream:: end); infile.tellg length = (); infile.seekg (0, ifstream:: beg); / / Allocate memory: buffer = new char [length]; / / Read data as a block: infile.read (buffer, length); infile.close (); / / Write to outfile outfile.write (buffer, length); outfile.close (); delete [] buffer; return 0;
    I have the same problem as before the files are readable even under notepad.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Convert Text File To Binary

    This program reads a text file, and outputs a matrix or permutation in internal format depending on the input to BinFile (default: P2). If the input file name is '=', input is read from stdin. If no arguments are given, T1 is used as input file and output goes to P2. Here are some examples:
    Command Conversion
    zcv T1 -> P2
    zcv txt Txt -> P2
    zcv txt z1 Txt -> z1
    zcv = z1 standard input -> z1

    To convert text from a file called `=' you must use input redirection:
    zcv = binfile < =

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: Convert Text File To Binary

    It might seem strange to you, but text files are binary, too. It's the application that treats them differently. For example, if you change the extension from .txt to .bin, the application will not handle it the same.

Similar Threads

  1. binary and text conversion java
    By Ronguor in forum Software Development
    Replies: 1
    Last Post: 14-03-2012, 01:24 PM
  2. Need help to convert a Text file to Excel via VBA Macro
    By DEvOTeEL in forum MS Office Support
    Replies: 1
    Last Post: 24-02-2012, 01:47 PM
  3. How to convert image text into a text file
    By Wadee in forum Windows Software
    Replies: 5
    Last Post: 02-12-2010, 06:33 PM
  4. How to convert text file to CSV
    By Yancy in forum Tips & Tweaks
    Replies: 3
    Last Post: 31-07-2009, 05:08 PM
  5. Convert Hex Value to Date from Binary Reg Key
    By RobT in forum Windows Server Help
    Replies: 4
    Last Post: 01-04-2005, 11:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,370,862.89444 seconds with 16 queries