Strange wofstream problem /bug

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Strange wofstream problem /bug

 
0
  #1
Feb 2nd, 2008
Here's good question for the gurus around here.

So we got a wofstream output.

In it I send using a recursive function time by time a CString data. Using off course the GetBuffer member to get a pointer to the content.

The problem is that it works really good till the 1207-calll.
Then suddenly the wostream becomes unusuable, invlaid and refuses to print anything else to it. The quuestion is why ?

I print with the tellp() the current size of the file and the result si something like this:

......
524336

524766

525226

525664

526154

526572

527140

527571

-1

-1

-1

-1
.......
The data sent t it is around 500 char long but shouldn't be a issue. Any ideas ? How to identify the problem ? The 1207th String is the same as the prior 1206 strings. Mainly composed of chars plus these simbols : [ ] and of course some spaces.
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #2
Feb 2nd, 2008
Some update: I get a "Fatal I/O error!" and the strange thing is that the first part of the item where it gets the error gets printed.
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #3
Feb 2nd, 2008
Got the problem. It was a char not known by my current Codecvt Facet.

Mainly this : ′ . At first I saw a few of the same type earlier added so I thougt that couldn't be a problem but it seems that my Codecvt Facet is old and I need to improve it.
Last edited by jokerjokerer; Feb 2nd, 2008 at 6:43 pm.
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,629
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Strange wofstream problem /bug

 
0
  #4
Feb 2nd, 2008
I'm glad you found the problem yourself because I for one have no idea what you were trying to describe. Never heard of wofstream or Codecvt Facet , but I am very familary for MFC's CString c++ class.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #5
Feb 2nd, 2008
Of the Codecvt Facet me neither until I meet with the problem. But hey we learn every day something new.
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #6
Feb 3rd, 2008
Ok traced back to the core the problem.

  1. CString omega = L"’";
  2. _tprintf(L"%s",omega.GetBuffer());

with result:
?
So the problem si to make the ’ appear on the screen cause as you can see the happens within a file. Just as the cout handles the ' char (code 8217) adn puts instead of it a ? mark a ofstream (wofstream -> for wide chars -Unicode) can't do the same and puts a fail flag.

So any solution out there ?

Strangely i tried to assign a beeter codecvt Facet to my ofstream file and I get some strange errors:

Well shortly presented. We have this code form the Boost site.

// My encoding type
typedef wchar_t ucs4_t;

std::locale old_locale;
std::locale utf8_locale(old_locale,new utf8_codecvt_facet<ucs4_t>);

// Set a New global locale
std::locale::global(utf8_locale);

// Send the UCS-4 data out, converting to UTF-8
{
std::wofstream ofs("data.ucd");
ofs.imbue(utf8_locale);
std::copy(ucs4_data.begin(),ucs4_data.end(),
std::ostream_iterator<ucs4_t,ucs4_t>(ofs));
}



And the error messages:


: error C2661: 'std::locale::facet::operator new' : no overloaded function takes 3 arguments
: error C2059: syntax error : ')'
: error C2065: 'utf8_locale' : undeclared identifier
: error C2065: 'ucs4_data' : undeclared identifier
: error C2228: left of '.begin' must have class/struct/union

Any ideas why ? And mainly how to fix it ?

I'm using something wrong ? Any other advice.
Last edited by jokerjokerer; Feb 3rd, 2008 at 7:16 am.
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Strange wofstream problem /bug

 
0
  #7
Feb 3rd, 2008
>Never heard of wofstream or Codecvt Facet
wofstream is the wide character variant of ofstream. codecvt is basically meant for converting between different character encodings.

>Any ideas why ? And mainly how to fix it ?
I'd say that you either don't have Boost installed, didn't include the correct header, or both.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #8
Feb 3rd, 2008
And aI say neither.

I've added the source and made the declarations. Now if I wouldn't have Boost this line should be marked as compiler errors.

#define BOOST_UTF8_BEGIN_NAMESPACE namespace mynamespace {
#define BOOST_UTF8_END_NAMESPACE }
#define BOOST_UTF8_DECL
#include "boost\detail\utf8_codecvt_facet.hpp"


and the code you already know......
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #9
Feb 3rd, 2008
Can someone get to print (file or screan) this:

CString omega = L"’Ïðèâåò";


?
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Re: Strange wofstream problem /bug

 
0
  #10
Feb 4th, 2008
And here it is the answer to my question:

Method to write:

std::ofstream outFile("filename.dat", std::ios::out | std::ios::binary);
outfile.write((char *) wstr.c_str(), wstr.length() * sizeof(wchar_t));

Method to signal to the notepad that's Unicode:


wchar_t BOM = 0xFEFF;
std::ofstream outFile("filename.dat", std::ios::out | std::ios::binary);
outfile.write((char *) &BOM,sizeof(wchar_t));

Finally problem solved.
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC