473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
1 2926
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Julia | last post by:
Hi, I need to convert unicode string to ansi string Thanks in adavance.
5
by: Norman Diamond | last post by:
Here are two complete lines of output from Visual Studio 2005: 1>$B%W%m%8%'%/%H=PNO$K(B Authenticode $B=pL>$7$F$$$^$9(B... 1>Successfully signed: c:\T The first line means roughly: Doing...
2
by: Craig | last post by:
I have the need to write a byte of information to a specific location in a text file. eg. the file looks something like this. FYYNN Line 1 Line 2 <eof>
18
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that...
2
by: starffly | last post by:
I want to read a xml file in Unicode, UTF-8 or a native encoding into a wchar_t type string, so i write a routine as follows, however, sometimes a Unicode file including Chinese character cannot...
18
by: Chameleon | last post by:
I am trying to #define this: #ifdef UNICODE_STRINGS #define UC16 L typedef wstring String; #else #define UC16 typedef string String; #endif ....
23
by: Antony Clements | last post by:
i am using the following code private var1 as Long private var2 as Long private var3 as Long ReDim bytearray(0 To 3) ReDim bytearray2(0 To 3) For a = 0 To 3
4
by: xoinki | last post by:
hi all, I have a ini file in UTF-8, I am using GetPrivateProfileStringA() for reading and WriteprivateProfileStringA() for writing into the ini file. I am writing multibyte data into the file (using...
8
by: Ryanivanka | last post by:
hi ,everyone ,please check my codes,i am really confused. the codes of win32 dll is as follows: ***********************the win32 DLL writen in c++***************** extern "C" {...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.