C++ Can't use string in structs?
Go to solution
Solved by Nineshadow,
You don't have a constructor for the struct for it to work like that. Also, don't forget to include std::string.
You can, however, do something like this :
struct quiz_question{string var_type;string input_answer;string real_answerquiz_question(string str1 , string str2, string str3) { var_type = str1, input_answer = str2 , real_answer = str3;}};
Or with initialization lists :
struct quiz_question{string var_type;string input_answer;string real_answer;quiz_question(string str1 , string str2, string str3) : var_type(str1) , input_answer(str2) , real_answer(str3){}};
And use it like this:
quiz_question q("hello", "there" , "world");
Or just set those values :
quiz_question q;/* ... */q.var_type="char";

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now