Greetings community. I'm new to C++ and am seeking advice regarding how to store a variable match (==) as a new string. If I recall correctly, a bool statement can be used to store matching int variables, however I am looking for a command for storing string variables.
if (username_input == username_declaration)
{ // They match - Do something
}
else
{ // They don't match - do something else
}
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thank you for your response and my apologies, thank you shining light on the formatting tools. I greatly appreciate your response but, respectfully, it doesn't provide a solution to my challange. I am already familiar with if, else and else if statements.
Essentially, I desire to store an if condition as a new string. I want to declare a string called "username_input" ...where once read, the system will identify this string as the stored condition for "username_declaration == username_confirmation"
From what I've seen online something similar can be achieved for int's with a bool command. However, I am unfamiliar for how to achieve the similar result for strings (I've tried formatting it similarly to a bool format but it still doesn't work)
once read, the system will identify this string as the stored condition for "username_declaration == username_confirmation"
What do you mean by this? That the string will be "true" or "false"? Or that it will literally be "username_declaration == username_confirmation"? You can just assign the value to a boolean then print it:
1 2
bool username_input = ;username_declaration == username_confirmation;
std::cout<<username_input; //outputs 1 or 0 depending on the boolean value
If you want true or false: std::cout << std::boolalpha << username_input; //outputs 'true' or 'false'
Thank you for your response, the solutions you've provided seem interesting, as I'm a new learner.
To further elaborate, with reference to the intial code I provided above... let's say that I enter "cat" as my username_declaration and username_confirmation", which is recognised as a match (==)... I am curious as to whether I can assign a/that condition into "username_input" that will identify the match and thereby output the word "cat" automatically?
You're still not being vary clear. What is it that you want to store in username_input? A string, or a boolean? Saying you want to store "a condition" doesn't really mean anything.