473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Are C++ strings binary strings?

Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?

Thanks in advance.

Nov 1 '06 #1
9 1935
ruffiano wrote:
Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?

Thanks in advance.
What is a binary string? If what you mean by binary is something that is
stored in binary numbers then the answer to your question is both.

Ben
Nov 1 '06 #2
ruffiano wrote:
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
Nov 1 '06 #3
ruffiano wrote :
Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?
If your question is about whether you can put '\0' in std::strings then
yes, you can.
Nov 1 '06 #4
Victor Bazarov <v.********@comAcast.netwrote:
>ruffiano wrote:
>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?

Steve
Nov 1 '06 #5
Steve Pope wrote:
Victor Bazarov <v.********@comAcast.netwrote:
>ruffiano wrote:
>>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_string<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
Nov 1 '06 #6
"ruffiano" <ro************@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?

Thanks in advance.
std::string holds chars. Anything you can put into a char (0-255) can be put
into a std::string, so in this reference, it is binary.
Nov 2 '06 #7
"ruffiano" <ro************@yahoo.comwrote:
>Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?
"Jim Langston" <ta*******@rocketmail.comwrites:
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*chrome.pl>--ooO--(_)--Ooo--
Nov 3 '06 #8
ruffiano wrote:
Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?

Thanks in advance.
It's not necessarily either. It's std::string holds an arbitrary
number of whatever "char" is on your machine.

Nov 3 '06 #9

Michal Nazarewicz wrote in message <87************@erwin.mina86.com>...
>"ruffiano" <ro************@yahoo.comwrote:
>>Hi, can someone tell me if a C++ string (std::string) represents a
binary or an ASCII string?

"Jim Langston" <ta*******@rocketmail.comwrites:
>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.**
[ 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(unsigned char)<<std::endl;

cout <<"std::numeric_limits<char>::max() ="
<<int(std::numeric_limits<char>::max())<<std::endl ;
cout <<"std::numeric_limits<char>::min() ="
<<int(std::numeric_limits<char>::min())<<std::endl ;

cout <<"std::numeric_limits<unsigned char>::max() ="
<<int(std::numeric_limits<unsigned char>::max())<<std::endl;
cout <<"std::numeric_limits<unsigned char>::min() ="
<<int(std::numeric_limits<unsigned char>::min())<<std::endl;
}

/* -- output -- (MinGW(GCC), x86)
sizeof(char) =1
sizeof(unsigned char) =1
std::numeric_limits<char>::max() =127
std::numeric_limits<char>::min() =-128
std::numeric_limits<unsigned char>::max() =255
std::numeric_limits<unsigned char>::min() =0
*/

--
Bob R
POVrookie
Nov 3 '06 #10

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

Similar topics

17
7370
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
16
2400
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
5
5795
by: Robert Manea | last post by:
Hello everyone, I wrote, simply as an exercise, a small piece of code to find 'strings' (defined as an amount of at least 3 ASCII characters followed by a non ASCII character) in binary files. ...
9
5246
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
2
22569
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
8
1854
by: Allan Ebdrup | last post by:
What would be the fastest way to search 18,000 strings of an average size of 10Kb, I can have all the strings in memory, should I simply do a instr on all of the strings? Or is there a faster way?...
29
5052
by: Harlin Seritt | last post by:
Hi... I would like to take a string like 'supercalifragilisticexpialidocius' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in...
2
2240
by: testrasbath | last post by:
Why strings are not getting converted to binary form, even if we use BinaryWriter for writing to a file? Which is the similar technique in c# as ifstream(filename, ios::binary) in C++? My...
4
455
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
20
9358
by: tomPee | last post by:
Hi, I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following: Send over a socket: 1. Number of files to be send (not as an integer,...
0
7120
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
7373
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
5456
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,...
1
4897
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...
0
4583
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
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 ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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...

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.