Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem writing a Unicode File in ANSI code

Jaime Montes
Guest
 
Posts: n/a
#1: Jul 22 '05
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.

Alberto Barbati
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Problem writing a Unicode File in ANSI code


Jaime Montes wrote:[color=blue]
> 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).[/color]

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
Closed Thread