473,406 Members | 2,259 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,406 software developers and data experts.

basic_stringstream with unsigned short

Hi,
Given below is a traits with unsigned short. If i create a
stringstream with this traits will there be any problem.

struct XMLCh_traits
{
typedef unsigned short char_type;

typedef unsigned int int_type;

typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;

static void assign(char_type& __c1, const char_type& __c2)
{ __c1 = __c2; }

static bool eq(const char_type& __c1, const char_type& __c2)
{ return __c1 == __c2; }

static bool lt(const char_type& __c1, const char_type& __c2)
{ return __c1 < __c2; }

static int compare(const char_type* __s1, const char_type*
__s2, size_t __n)
{
for (size_t __i = 0; __i < __n; ++__i)
if (!eq(__s1[__i], __s2[__i]))
return lt(__s1[__i], __s2[__i]) ? -1 :
1;
return 0;
}

static size_t length(const char_type* __s)
{
const char_type* __p = __s;
while (*__p) ++__p;
return (__p - __s);
}

static const char_type* find(const char_type* __s, size_t __n,
const char_type& __a)
{
for (const char_type* __p = __s; size_t(__p - __s) <
__n; ++__p)
if (*__p == __a) return __p;
return 0;
}

static char_type* move(char_type* __s1, const char_type* __s2,
size_t __n)
{ return (char_type*) memmove(__s1, __s2, __n *
sizeof(char_type)); }

static char_type* copy(char_type* __s1, const char_type* __s2,
size_t __n)
{ return (char_type*) memcpy(__s1, __s2, __n *
sizeof(char_type)); }

static char_type* assign(char_type* __s, size_t __n, char_type
__a)
{
for (char_type* __p = __s; __p < __s + __n; ++__p)
assign(*__p, __a);
return __s;
}

static char_type to_char_type(const int_type& __c)
{ return char_type(__c); }

static int_type to_int_type(const char_type& __c)
{ return int_type(__c); }

static bool eq_int_type(const int_type& __c1, const int_type&
__c2)
{ return __c1 == __c2; }

static int_type eof() { return static_cast<int_type>(-1); }

static int_type not_eof(const int_type& __c)
{ return eq_int_type(__c, eof()) ? int_type(0) : __c; }

};

//typedef unsigned short XMLCh;
typedef std::basic_string<unsigned short, XMLCh_traitsuString;
typedef std::basic_stringstream<unsigned short, XMLCh_traits>
uStringStream;
unsigned short result;
//this _U is macro which uses XMLString::transcode
//to get a XMLCh* out of char*
uString str(_U("123"));
uStringStream stream(str);
stream>>result; // debugger showes this line causes aborting
cout<<result<<endl;

The program is getting ABORTED. Could any one tell me why ?

Thanks in Advance
Kiran Pradeep.

Oct 30 '06 #1
1 2839
wolverine wrote:
Hi,
Given below is a traits with unsigned short. If i create a
stringstream with this traits will there be any problem.

struct XMLCh_traits
snip
};

//typedef unsigned short XMLCh;
typedef std::basic_string<unsigned short, XMLCh_traitsuString;
typedef std::basic_stringstream<unsigned short, XMLCh_traits>
uStringStream;
unsigned short result;
//this _U is macro which uses XMLString::transcode
//to get a XMLCh* out of char*
uString str(_U("123"));
uStringStream stream(str);
stream>>result; // debugger showes this line causes aborting
cout<<result<<endl;

The program is getting ABORTED. Could any one tell me why ?
The string_stream does not only depend on char_traits, but also on locale
info implemented for your characetr type. In this case operator>>(unsigned
short&) is looking for a std::ctype<XMLCh>, which isn't available.
Fixing the std::locale for a new char type is really, really hard to do.
:-(
Bo Persson
Oct 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy | last post by:
I am using basic_stringstream for creating character set neutral strings. If I use it like this: basic_stringstream<wchar_t> str1, str2; /*1*/ str1<<"A="<<int1<<"; B="<<chr2<<";...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
20
by: Hanzac Chen | last post by:
Hi, I don't understand why this could happen? The Code 1 will output `fff9' and the Code 2 will output `1' How could the `mod 8' not have effect? /* Code 1 */ #include <stdio.h> #include...
4
by: slougheed | last post by:
I encountered a problem after we had converted our declarations of 'unsigned short int' to uint16_t. In one instance, whoever did the conversion failed to delete the 'short' keyword so we had a...
0
by: wolverine | last post by:
Hi, Given below is a traits with unsigned short. If i create a stringstream with this traits will there be any problem. //typedef unsigned short XMLCh; //The XMLCh_traits is defined below ...
10
by: Jim Langston | last post by:
Is the following well defined? size_t IntVal = 65537; unsigned short Length; if ( IntVal static_cast<unsigned short>( -1 ) ) { std::cout << "Value too long to fit in a short" << std::endl;...
6
by: Kislay | last post by:
Consider the following code snippet unsigned int i=10; int j= - 2; // minus 2 if(i>j) cout<<"i is greater"; else cout<<"j is greater"; Since i is unsigned , j is greater . I know why , but...
3
by: mathieu | last post by:
Could someone please tell me what is wrong with the following -ugly- piece of c++ code. Why when I explicititely set the template parameter my gcc compiler start getting confused: bla.cxx: In...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.