Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?
What's "a binary string"?
It stores an array of 'char' values. That's all. 'ASCII' is a way
to interpret a 'char' value as a printable character. Those two
things are orthogonal. If you want to see an 'std::string' as
a container of ASCII characters, power to you. On a different system
somebody else might see it as a container of EBCDIC characters. Or
a container of extended ASCII.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>Hi, can someone tell me if a C++ string (std::string) represents a
>binary or an ASCII string?
>What's "a binary string"?
>It stores an array of 'char' values. That's all. 'ASCII' is a way
>to interpret a 'char' value as a printable character. Those two
>things are orthogonal. If you want to see an 'std::string' as
>a container of ASCII characters, power to you. On a different system
>somebody else might see it as a container of EBCDIC characters. Or
>a container of extended ASCII.
I think the question is whether a string element is guaranteed
to represent all 2^k binary values of a k-bit character, and
exhibit normal binary arithmetic, or whether it's guarateed only to
represent those values from a character set.
Some very, very old computers would have character-set-specific
logic functions (compare, increment, etc.) and one could envision
a character type, hence a string type on such a machine not
behaving correctly if used instead as a binary number.
The odds of running into this are extremely low. What does
the language say?
>>Hi, can someone tell me if a C++ string (std::string) represents a
>>binary or an ASCII string?
>
>What's "a binary string"?
>
>It stores an array of 'char' values. That's all. 'ASCII' is a way
>to interpret a 'char' value as a printable character. Those two
>things are orthogonal. If you want to see an 'std::string' as
>a container of ASCII characters, power to you. On a different system
>somebody else might see it as a container of EBCDIC characters. Or
>a container of extended ASCII.
>
I think the question is whether a string element is guaranteed
to represent all 2^k binary values of a k-bit character, and
exhibit normal binary arithmetic, or whether it's guarateed only to
represent those values from a character set.
>
Some very, very old computers would have character-set-specific
logic functions (compare, increment, etc.) and one could envision
a character type, hence a string type on such a machine not
behaving correctly if used instead as a binary number.
>
The odds of running into this are extremely low. What does
the language say?
You lost me. According to the language, 'std::string' is a typedef
of 'std::basic_str ing<char>'. The template 'basic_string' has some
requirements specified for it in the Standard, but none of them
mention "binary" or "ASCII". What exactly is it the OP wanted to
know? And perhaps let the OP answer this.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>Hi, can someone tell me if a C++ string (std::string) represents a
>binary or an ASCII string?
"Jim Langston" <tazmaster@rock etmail.comwrite s:
Anything you can put into a char (0-255)
The range you've given is wrong or at least misleading. I haven't had
much experience with various platforms but I've never seen a compiler
which treated char as unsigned by default, and with unsigned chars the
range would be rather -128..127. Still however, on platforms with
ones' complement the range would be -127..127. Still however, char
does not need to have 8 bits (it is guaranteed to have at least 8 bits
though) so the range could be completely different.
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl >---<jid:mina86*chr ome.pl>--ooO--(_)--Ooo--
>
>The range you've given is wrong or at least misleading. I haven't had
>much experience with various platforms but I've never seen a compiler
>which treated char as unsigned by default,
**and with unsigned chars the range would be rather -128..127.**
[ Let's not mislead newbies <G]
I think Michal meant 'signed char', not 'unsigned char'.
#include <limits// and <iostream>, <ostream>
{
using std::cout // for NG posting
cout<<" sizeof(char) ="<<sizeof(char )<<std::endl;
cout<<" sizeof(unsigned char) ="<<sizeof(unsi gned char)<<std::end l;
Comment