Problem writing a Unicode File in ANSI code

J

Jaime Montes

I have found that adding in the start of the file the character '-1'
and '-2' I can read the file as a Unicode, and to write any character
I have to write pairs of character so for 'a' I write '0' + 'a'. My
problem is that when I write '\n' or char(10) the ofstream write
char(13) + char(10) when I only need it write char(10), so I want to
remove the char(13) but I don't have a clue in how to do it.

I found this checking the file with a hex editor. I have try with the
class studio.h with the FILE, with the class fstream with ofstream and
ifstream, and the two give the same result when I have to write
char(10) it write char(13) + char(10).

I paste a simple code that the funtion is only copy 1 file to other.

#include <iostream.h>
#include <fstream.h>

class Unicode{
ofstream exit;
ifstream enter;
char enterFile[25], exitFile[25];

public:
void readEnterFile(){
cout<<"Enter File: ";
cin>>enterFile;
enter.open(enterFile);
if(enter.fail())
throw "Fail opening original file";
}

void readExitFile(){
cout<<"File to write: ";
cin>>exitFile;
exit.open(exitFile);
if(exit.fail())
throw "Fail opening original file";
}

void copyFile(){
char temp;
enter.get(temp);
while(!enter.eof()){
exit.put(temp);
enter.get(temp);
}
enter.close();
exit.close();
}

};

main(){
Unicode U;
U.readEnterFile();
U.readExitFile();
U.copyFile();
return 0;
}

I use the code above to copy a Unicode File to other but I find the
problem mention before.
 
A

Alberto Barbati

Jaime said:
I found this checking the file with a hex editor. I have try with the
class studio.h with the FILE, with the class fstream with ofstream and
ifstream, and the two give the same result when I have to write
char(10) it write char(13) + char(10).

Just open the output file as binary, that is:

f = fopen("filename", "wb"); // for stdio.h files
f.open("filename", std::ios_base::binary); // for iostream files

Alberto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top