Converting string to bool
-
you misunderstood me. I meant what is contained within that string ? 1/0 ? true/false ? checked/unchecked ? white/black ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
true/false :) (well, that what he said in his post)
Cédric Moonen Software developer
Charting control [v1.4] -
true/false :) (well, that what he said in his post)
Cédric Moonen Software developer
Charting control [v1.4]I prefer to be sure... :-D
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
what about
bool f = temp == "true";
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Thanks for the reply. This can be done. But instead I am looking for some function that does this like atoi() or itoa() for string to int and vice versa. Is there any function for strings to bool.
pl_kode wrote:
But instead I am looking for some function that does this like atoi() or itoa() for string to int and vice versa
Why ? That's quite simple, why do you want to use an existing function for that ?
pl_kode wrote:
Is there any function for strings to bool.
Not as far as I know.
Cédric Moonen Software developer
Charting control [v1.4] -
You still remember it. :laugh: Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Well I forgot for a while, but then suddenly I spotted you vulture ;P ready for hitting me! :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Thanks for the reply. This can be done. But instead I am looking for some function that does this like atoi() or itoa() for string to int and vice versa. Is there any function for strings to bool.
Good news: it exists, is
atob
. The bad news is that you have to code it (anyway you got so many hints about). :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
you misunderstood me. I meant what is contained within that string ? 1/0 ? true/false ? checked/unchecked ? white/black ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
I am getting a string from map that can be either true or false. Is there any function or some alternative to convert this string into bool. So that I can store it in a bool variable.
string temp;
temp=MyMap.find("Check")->second; // give either true or falseI want to convert temp to bool. THANKS.
bool bVal = (temp == "true"?true:false);
-@SuDhIrKuMaR@-
-
Well I forgot for a while, but then suddenly I spotted you vulture ;P ready for hitting me! :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
bool bVal = (temp == "true"?true:false);
-@SuDhIrKuMaR@-
why do you need the ?: operator ? the std::string::operator==() already returns a bool. in the same direction, why wouldn't you write this then :
bool bVal = ((temp == "true") == true ? true : false)
or
bool bVal = (((temp == "true") == true) == true ? true : false)
or just
bool bVal = (temp == "true")
;P
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]