473,669 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::bitset construction with std::string question

Can anyone tell me why

std::bitset<2> foo(std::string ("01"))

initializes the bitset in reverse order, i.e.

foo[0]=true
foo[1]=false

I would expect the bitset to be initialized in string text order.
Jul 19 '05 #1
2 3609

"Dill Hole" <di******@micro soft.com> wrote in message
news:7b******** *************** *********@4ax.c om...
Can anyone tell me why

std::bitset<2> foo(std::string ("01"))

initializes the bitset in reverse order, i.e.

foo[0]=true
foo[1]=false

I would expect the bitset to be initialized in string text order.


I wouldn't,

6 = 110 = 1*2^2 + 1*2^1 + 0*2^0 == foo[2] is 1, foo[1] is 1, foo[0] is 0.

In other words its a consequence of the fact that in English numbers the
most signficant digit goes first.

john
Jul 19 '05 #2

Dill Hole <di******@micro soft.com> wrote in message
news:7b******** *************** *********@4ax.c om...
Can anyone tell me why

std::bitset<2> foo(std::string ("01"))

initializes the bitset in reverse order, i.e.

foo[0]=true
foo[1]=false

I would expect the bitset to be initialized in string text order.


See John H's reply, then observe the output of:

cout << foo << '\n';

-Mike

Jul 19 '05 #3

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

Similar topics

19
22727
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give the std::string a pointer and a length and then give the std::string control over the pointer and its content? I'm basically trying to avoid copying large text between an std::string and a char pointer, and vice versa. Is there anyhing in the...
11
3647
by: Christopher Benson-Manica | last post by:
Let's say I have a std::string, and I want to replace all the ',' characters with " or ", i.e. "A,B,C" -> "A or B or C". Is the following the best way to do it? int idx; while( (idx=str.find_first_of(',')) >= 0 ) { str.replace( idx, 1, "" ); str.insert( idx, " or " ); }
5
5473
by: SpOiLeR | last post by:
Hi. q1: Is std::bitset<N> part of standard or it's compiler extension? q2: Is std::bitset::to_string() part of standard? q3: My documentation say this about std::bitset::to_string(): "...each character is 1 if the corresponding bit is set, and 0 if it is not. In general, character position i corresponds to bit position N - 1 -
19
6138
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not found anything). Here's the problem, I have two sets of files, the name of a file contains a number which is unique for each set but it's possible (even probable) that two files in different sets have the same numbers. I want to store these...
16
16414
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
12
13574
by: jl_post | last post by:
Dear C++ community, I have a question regarding the size of C++ std::strings. Basically, I compiled the following code under two different compilers: std::string someString = "Hello, world!"; int size1 = sizeof(std::string); int size2 = sizeof(someString); and printed out the values of size1 and size2. size1 and size2 always
14
3019
by: Haro Panosyan | last post by:
How to construct a bitset from string? For example: std::bitset<16> b16("1011011110001011"); Is this possible? Thanks in advance. -haro
8
8316
by: vidya.bhagwath | last post by:
Hello Experts, I am using std::string object as a member variable in one of the my class. The same class member function operates on the std::string object and it appends some string to that object. My sample code is as follows. ..h file content---------- #include <stdio.h>
2
1824
by: mathieu | last post by:
Hi there, I must be doing something wrong, but I do not understand the documentation for bitset( string ), shouldn't this be equivalent (ref == mask ) ? #include <bitset> #include <iostream> #include <string>
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
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
8803
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8587
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
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
4206
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...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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
2
1787
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.