Converting string to bool
-
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.
-
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 bChecked = false;
if (temp == "true")
bChecked = true;:~. You have to check for the case also but you got the idea.
Cédric Moonen Software developer
Charting control [v1.4] -
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.
what kind of strings are supposed to be stored in
MyMap.find("Check")->second
? I mean, you'll have to test programmatically the string to assign another boolean variable to true or false...[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.
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 -
bool bChecked = false;
if (temp == "true")
bChecked = true;:~. You have to check for the case also but you got the idea.
Cédric Moonen Software developer
Charting control [v1.4] -
what kind of strings are supposed to be stored in
MyMap.find("Check")->second
? I mean, you'll have to test programmatically the string to assign another boolean variable to true or false...[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
what kind of strings are supposed to be stored in MyMap.find("Check")->second ?
From his snippet of code, I would say std::string.
Cédric Moonen Software developer
Charting control [v1.4] -
toxcct wrote:
what kind of strings are supposed to be stored in MyMap.find("Check")->second ?
From his snippet of code, I would say std::string.
Cédric Moonen Software developer
Charting control [v1.4]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]
-
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.
please reply to this question[^] first before we can reply to you efficiently
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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@-
-
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]
-
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