473,386 Members | 1,712 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,386 software developers and data experts.

bitset

Hello.

Can anyone tell me why you have to explicitly write the template parameters
in the .to_string() method? e.g:

bitset<8> bit(string("11"));
cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl;

...
Jul 19 '05 #1
3 3952

"Anders" <anders> wrote in message
news:3f***********************@dread16.news.tele.d k...
Hello.

Can anyone tell me why you have to explicitly write the template parameters in the .to_string() method? e.g:

bitset<8> bit(string("11"));
cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl;


Noramlly which version of a template function is called is worked out based
on the types of the parameters of that function. Since to_string does not
have any parameters you have to tell the compiler explicitly which kind of
string you want returned.

john
Jul 19 '05 #2
"Anders" <anders> wrote...
Can anyone tell me why you have to explicitly write the template parameters in the .to_string() method? e.g:

bitset<8> bit(string("11"));
cout << bit.to_string<char, char_traits<char>, allocator<char> >() <<

endl;

Because 'to_string' is a template member. You only need to specify
the first one, by the way: bit.to_string<char>()

However, *I* don't have to do that to output the actual bitset:

#include <bitset>
#include <iostream>
#include <string>

using namespace std;

int main()
{
bitset<8> bit(string("11"));
cout << bit << endl;
}

works fine for me. It prints
00000011

Victor
Jul 19 '05 #3

"Anders" <anders> wrote in message news:3f***********************@dread16.news.tele.d k...
Hello.

Can anyone tell me why you have to explicitly write the template parameters
in the .to_string() method? e.g:

bitset<8> bit(string("11"));
cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl;


Functions are not overloaded by return value. It doesn't know what kind of
string you wanted to convert it to.

Jul 19 '05 #4

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

Similar topics

6
by: Hunter Hou | last post by:
Hello, I have this very simple program, but it can't be compiled. What's wrong here? thanks, hunter #include <iostream>
2
by: shaun roe | last post by:
As a follow up to my question about STL and bitset<64> I'd like to share a quirk (bug?) about unsigned long long support and the bitset. I'm using gcc 3.2 on linux or gcc 3.3 on mac, the answer is...
5
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(): ...
5
by: Rich S. | last post by:
Hi, Is the code below the best way to have the less than function for an 80 bit bitset or is there something faster / better? When I populate this map with millions (... and millions) of sets...
14
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
3
by: shaun | last post by:
I have a function for returning the value of a bit field in a number: template<typename T> T bitfield(const T num, const unsigned int bitStart, const unsigned int bitEnd){ T mask,...
4
by: Sarath | last post by:
>From the documentation of MSDN, it is saying that bitset is not a STL container Unlike the similar vector<boolClass, the bitset class does not have iterators and is not an Standard Template...
2
by: arnuld | last post by:
i am confused on some aspects of bitset class: /* C++ Primer 4/e * chapter 3 * * exercise 3.23 * */ #include <iostream>
5
by: arnuld | last post by:
i have solved the problem. any comments on it: /* C++ Primer 4/e * chapter 3 * * exercise 3.24 * STATEMENT: * consider the sequence 1,2,3,5,13,21. Initialize a "bitset<32>" object that...
5
by: swcamry | last post by:
class bitset::reference { friend class bitset; reference(); // no public constructor public: ~reference(); operator bool () const; //...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.