Strings and Boolean

G'day guys,

I am currently at work and have some time to kill so i thought I would ask a question about strings and booleans I was going to try out when I get home tonight.

So I used to dabble in C++ a number of years ago as I enjoy it, anyway I have had some time lately and I am trying to pick things back up. I was typing something up last night and I would like to implement a bool into it that’s determined by the cin of a string. So could someone be so kind to tell me if the following would work;

#include <iostream>
#include <string>

main ()
{
  bool stag = false;
  std::string staggered;

  std::cout << "Is the piquet double staggered?: " << endl;
  std::getline (std::cin,staggered);

  if (std::string staggered == "yes" || "Yes") {
    stag = true;
    }

  return 0;
}


Like I said I am not at home, other wise I would post in my code to give you a better idea at what I am trying to achieve.
1
2
3
4
5
6
int main()
...
if (staggered == "yes" || staggered == "Yes") {
/*OR
declare stag on the same line it is first used*/
bool stag = (staggered == "yes" || staggered == "Yes");
Last edited on
ah right thanks, so if I use one of the above I can then later use;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
... 
if (stag == true) {
  int1 = (int2 + int2) * 2;      // Random values from user input
  } else {
      int1 = int2 + int3;
      }
/* 
OR
*/
if (staggered == "yes" || staggered == "Yes") {
  int1 = (int2 + int3) * 2;      // Random values from user input
  } else {
     int1 = int2 + int3;
     }


Also is there anything stopping me from using multiple "or's" in my if statement or anywhere else for that matter? for e.g;

1
2
if (staggered == "yes" || staggered == "Yes" || staggered == "YES" || staggered == "y") ....
...


Thanks again
Topic archived. No new replies allowed.