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

Using: bitset( string() )

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>

int main()
{
std::bitset<8ref( 13ul );
std::cout << ref << std::endl;

const char v[] = "1101";
std::bitset<8mask( std::string(v) );
std::cout << mask << std::endl;
return 0;
}
Thanks
-Mathieu
Jun 27 '08 #1
2 1808
On 2008-05-06 07:02:00 -0400, mathieu <ma***************@gmail.comsaid:
#include <bitset>
#include <iostream>
#include <string>

int main()
{
std::bitset<8ref( 13ul );
std::cout << ref << std::endl;

const char v[] = "1101";
std::bitset<8mask( std::string(v) );
std::cout << mask << std::endl;
return 0;
}
You've stepped into a funky corner of C++ syntax. This code declares
mask to be a function, and the compiler converts its address to a bool
to insert it into a stream. Break up the definition of mask:

std::string str(v);
std::bitset<8mask(str);

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jun 27 '08 #2
On May 6, 1:14 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2008-05-06 07:02:00 -0400, mathieu <mathieu.malate...@gmail.comsaid:
#include <bitset>
#include <iostream>
#include <string>
int main()
{
std::bitset<8ref( 13ul );
std::cout << ref << std::endl;
const char v[] = "1101";
std::bitset<8mask( std::string(v) );
std::cout << mask << std::endl;
return 0;
}

You've stepped into a funky corner of C++ syntax. This code declares
mask to be a function, and the compiler converts its address to a bool
to insert it into a stream. Break up the definition of mask:

std::string str(v);
std::bitset<8mask(str);
Thanks ! That was it.
Jun 27 '08 #3

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

Similar topics

2
by: Neil Zanella | last post by:
Hello, Consider the following program. There are two C style string stack variables and one C style string heap variable. The compiler may or may not optimize the space taken up by the two stack...
5
by: Jason | last post by:
Hi all basically its what i said in the subject. Would just like to know how to split a string using a STRING value as the delimeter and not a CHAR as the delimeter. Example: "I like Cheese",...
18
by: A.M | last post by:
Hi, Is there any way to call a WSS web service method by using browser and see the XML result in browser as well? I have been told that there is query string syntax for calling...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
3
by: doubts | last post by:
Hi all, I am trying to convert my bulk of code from VC++ 6.0 to VC++.Net. when using std::string type variable, the application causes exception at one instance and does not cause an exception at...
5
by: Assertor | last post by:
Hi, all. Is there any way to create an instance of std::ifstream using std::string. (through std::ifstream's constructor or assignment operator or iterator, etc...) i.e. std::string str =...
11
by: Peter Olcott | last post by:
Does C++ have anything like this?
11
by: dolphin | last post by:
Hi All! I have a question that how to call a function just using a string. For example There is a .cpp file named a.cpp.There are some functions::fun1() fun2() fun3(). I have another fucntion...
2
by: donthomasino | last post by:
i get error c2886( when i use using std::cout; using std::string;) and when i change to (using namespace std; using namespace std;) i got error c2059 #include <iostream> #include <string>...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.