Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Reading unicode text files

Reply
Thread Tools

Reading unicode text files

 
 
Wx
Guest
Posts: n/a
 
      05-22-2007
Hello.

I'm trying to read a textfile written by the NTBackup utility on
Windows 2003 SBS. The problem is that when i print the output, it
looks like this:

S t a t o : b a c k u p
O p e r a z i o n e : b a c k u p
D e s t i n a z i o n e b a c k u p a t t i v o : F i l e
N o m e s u p p o r t o : " l u m e v e . b k f c r e a t o i
l 2 1 / 0 5 / 2 0 0 7 a l l e 2 3 . 0 0 "

As you can see, there is a space prior to any charater. I know that
unicode characters uses two bytes, so... can be the problem related to
different charset?

If I try to read a new textfile, there are no problem.

This is the relevant portion of the code:


try {
ifstream infile(strLogFile.c_str());

if (infile.is_open()) {
string line;
while (getline(infile, line)) {
cout << line << endl;
}

infile.close();

} else {
cerr << "Impossibile aprire " << strLogFile << endl;
return false;
}

Excuse me for my english.
Thanks

Wx

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      05-22-2007
* Wx:
>
> I'm trying to read a textfile written by the NTBackup utility on
> Windows 2003 SBS. The problem is that when i print the output, it
> looks like this:
>
> S t a t o : b a c k u p
> O p e r a z i o n e : b a c k u p
> D e s t i n a z i o n e b a c k u p a t t i v o : F i l e
> N o m e s u p p o r t o : " l u m e v e . b k f c r e a t o i
> l 2 1 / 0 5 / 2 0 0 7 a l l e 2 3 . 0 0 "
>
> As you can see, there is a space prior to any charater. I know that
> unicode characters uses two bytes, so... can be the problem related to
> different charset?


Yes. The "spaces" are, at least before they end up in your program,
zero bytes.


> If I try to read a new textfile, there are no problem.
>
> This is the relevant portion of the code:
>
>
> try {
> ifstream infile(strLogFile.c_str());


Well, it doesn't help you to use a wide character stream, because they
simply convert to/from external narrow character data.

What you can do is open the file in binary mode.

Then read the contents as binary data and treat as a sequence of wchar_t
values (e.g., you can just store them in a std::wstring).

Essentially this means implementing the machinery that the standard
library provides for narrow character streams. Or, you can buy an
existing implementation or find one on the net (I doubt you'll find
one). I think Dinkumware offers such an implementation.

Note that handling wchar_t in Windows leads you into compiler-specific
territory, since e.g. MingW g++ 3.4.4 doesn't support wide character
streams.


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unicode and reading/writing text files Devin ASP General 1 11-19-2008 06:19 PM
Batchfiles, Pipe > Output.txt, Redirection might fail with Unicode text files ?!?!?! Skybuck Flying Windows 64bit 0 01-20-2008 09:22 PM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
reading the DB vs. reading a text file...performance preference? Darrel ASP .Net 3 11-11-2004 02:27 PM
how do I read unicode text files? Boris C++ 0 10-28-2003 10:52 AM



Advertisments