Google Groups Home
Help | Sign in
Streaming a wstring to a wofstream
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Edward Diener  
View profile
 More options Jul 25, 2:08 pm
Newsgroups: comp.lang.c++.moderated
From: Edward Diener <diener896092_no_spam_h...@bellsouth.net>
Date: Fri, 25 Jul 2008 12:08:57 CST
Local: Fri, Jul 25 2008 2:08 pm
Subject: Streaming a wstring to a wofstream
Is there ever any case in which streaming a wstring to a wofstream
should fail to write all the characters in the wstring to the file ? In
code, built with VC9 in Windows, I have:

std::wstring astring;
// Code that fills the wstring with about 210,000 wide characters.
// I can verify the size of this in the debugger.
std::wofstream wofs("somefile",std::ios_base::out | std::ios_base::binary);
wofs << astring;
// wofs gets closed by going out of scope

When I check the file written it is truncated after about 93000 bytes or
half that many wide characters.

In other cases when streaming a much smaller ( 50 characters or so )
wstring using a wofstream the output is correct.

Ideas ? Or just a possible bug in VC9 which I need to duplicate and
presenrt to Microsoft ?

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oncaphillis  
View profile
 More options Jul 25, 8:28 pm
Newsgroups: comp.lang.c++.moderated
From: Oncaphillis <oncaphil...@snafu.de>
Date: Fri, 25 Jul 2008 18:28:26 CST
Local: Fri, Jul 25 2008 8:28 pm
Subject: Re: Streaming a wstring to a wofstream

Edward Diener wrote:
> Is there ever any case in which streaming a wstring to a wofstream
> should fail to write all the characters in the wstring to the file ? In
> code, built with VC9 in Windows, I have:

> std::wstring astring;
> // Code that fills the wstring with about 210,000 wide characters.
> // I can verify the size of this in the debugger.
> std::wofstream wofs("somefile",std::ios_base::out |
> std::ios_base::binary); wofs << astring;

  Did you check the streams internal state after writing ?
i.e.

  if(!wofs) {
    std::cerr << "somethings fishy" << std::endl;

}
> // wofs gets closed by going out of scope

> When I check the file written it is truncated after about 93000 bytes or
> half that many wide characters.

Are you *really* writing wchar_t to the underlying file i.e. uint(16|32) ?
Or is the wofstream only a front end for a byte based encoding like
utf8 or a JIS variant or..or..or ?

  Is the stream properly imbued ? If so to which locale ?
  If you use a codecvt facet that does not support the
utf-16/32 code (I assume your wchar_t is meant to
  hold unicode) writing might be canceled although
the g++ implementation throws an exception in that case.

(Hmm -- makes me wonder, isn't it forbidden for iostream operations
to throw exceptions ?. Or was there some kind of flags to manipulate
this behavior ?)

> In other cases when streaming a much smaller ( 50 characters or so )
> wstring using a wofstream the output is correct.

> Ideas ? Or just a possible bug in VC9 which I need to duplicate and
> presenrt to Microsoft ?

Anyway -- just my 6¢ before you think about mailing Bill -- oh no wait --
he retired it's Steve now.

HTH

O.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google