473,804 Members | 3,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

basic_stringstr eam 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_typ e& __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_typ e)); }

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

static char_type* assign(char_typ e* __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(co nst int_type& __c)
{ return char_type(__c); }

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

static bool eq_int_type(con st 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_stri ng<unsigned short, XMLCh_traitsuSt ring;
typedef std::basic_stri ngstream<unsign ed short, XMLCh_traits>
uStringStream;
unsigned short result;
//this _U is macro which uses XMLString::tran scode
//to get a XMLCh* out of char*
uString str(_U("123"));
uStringStream stream(str);
stream>>result; // debugger showes this line causes aborting
cout<<result<<e ndl;

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

Thanks in Advance
Kiran Pradeep.

Oct 30 '06 #1
1 2887
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_stri ng<unsigned short, XMLCh_traitsuSt ring;
typedef std::basic_stri ngstream<unsign ed short, XMLCh_traits>
uStringStream;
unsigned short result;
//this _U is macro which uses XMLString::tran scode
//to get a XMLCh* out of char*
uString str(_U("123"));
uStringStream stream(str);
stream>>result; // debugger showes this line causes aborting
cout<<result<<e ndl;

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>>(unsi gned
short&) is looking for a std::ctype<XMLC h>, 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
2154
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<<"; C="<<str1<<std::endl; ...
34
16694
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 - 3;
16
5153
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. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
20
5369
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 <stdlib.h>
4
5214
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 'uint16_t short'. The compiler (GNU 3.3.5) allows this but ignores the original unsigned keyword and initialzes the variable as a signed short int. I created a very simple test program just to see what was happening: #include <stdio.h> ...
0
246
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 typedef std::basic_string<unsigned short, XMLCh_traitsuString; typedef std::basic_stringstream<unsigned short, XMLCh_traits> uStringStream;
10
5653
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; } else
6
6462
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 vaguely . Can
3
6411
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 function 'int main()': bla.cxx:25: error: call of overloaded 'foo(short unsigned int*&)' is ambiguous bla.cxx:2: note: candidates are: void foo(OutputType*) bla.cxx:10: note: void foo(PixelType*)
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.