467,207 Members | 1,277 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,207 developers. It's quick & easy.

Problem writing a Unicode File in ANSI code

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.
Jul 22 '05 #1
  • viewed: 2319
Share:
1 Reply
Jaime Montes wrote:
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Norman Diamond | last post: by
18 posts views Thread by mollyf@hotmail.com | last post: by
2 posts views Thread by starffly@gmail.com | last post: by
18 posts views Thread by Chameleon | last post: by
23 posts views Thread by Antony Clements | last post: by
8 posts views Thread by Ryanivanka | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.