text file ASCII converting

hello all,
i am new and in need of assistance. i am trying to convert the contents of a .txt to ASCII values and save it as a separate .txt file. im not sure how to do this. can anyone help me?
So are you saying that the encoding of your input is not ASCII, or that you want to convert each character to a number and save it?
yes, i want to convert each character.
You're misunderstanding several concepts here. Forget about ASCII completely, just erase it from your mind.

Files are made up of bytes. You can interpret a file however you want - be it as text, or as a bunch of numbers, but the content is the same either way.
ok so then i want to change the bytes?
No, you want to interpret the bytes as numbers, and convert those numbers to strings with spaces between each one. You won't be 'changing' anything.
Last edited on
ok, i think i understand that now. how would i tell the program to read it differently?
Last edited on
All you have to do is tell your program to write it differently. Read your file into a buffer, then extract from the buffer one character at a time.

http://www.parashift.com/c++-faq/print-char-or-ptr-as-number.html
Thats helpful, thanks. Now how do i get it to read from an external file?
the fstream class. http://www.cplusplus.com/reference/fstream/fstream/ There are also a pile of examples you can look up easily enough.
Also there is a tutorial on file input and output:
http://www.cplusplus.com/doc/tutorial/files/

I'd suggest you may find the get() function useful for reading one character at a time from the input file. Then you simply need to output that char as an int, and repeat.
http://www.cplusplus.com/reference/istream/istream/get/
Topic archived. No new replies allowed.