+ 2
How to declare a string variable in c++
I have a program where I want to declare a string g variable by setting it equals "success" or "fail" based on user input. I don't want to output the string directly but want to store it in a variable so as to use for further test in the code.
2 Answers
+ 5
Use the string class :
string g = "Fail";
int a; cin>>a;
if(a) g="Success";
// Do other stuff.
You need the <string> header for this.
For more information on the string type, visit:
www.cplusplus.com/reference/string
Edit - Glad to be able to help. ^_^
+ 2
https://code.sololearn.com/c0s4Lpw397Ow/?ref=app
Thanks it works for me. I tested it using above sample before implementing it to my project.