Sep 12, 2013 at 12:38pm Sep 12, 2013 at 12:38pm UTC
what are the exact steps that leads to the crash? Where does it crash (line)?
the use of map<int ,Questions> questions
is questionable. At least you generate a memory leak.
Sep 12, 2013 at 1:07pm Sep 12, 2013 at 1:07pm UTC
I suspect there may be problems due to mixing of cin >>
and getline()
.
These can be used together, but care needs to be taken over the sequence in which they are used, and ensure that any trailing newline has been cleared from the input buffer before attempting a getline.
Sep 12, 2013 at 2:08pm Sep 12, 2013 at 2:08pm UTC
No idea why it crashes just pointing out where it does.
Can array indexing be used for choic?
What is returned by get_cho()?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
if (temper==1)
{
Choices* choic=new RadioBoxes[count];
//cout<<&choic[0]<<endl;
//cout<<&choic[1]<<endl;
q1->set_cho(choic);
// sur.questions[i][0].
//cout<<q1->get_cho()->get_type();
q1->set_choices(count);
sur.questions[i]=*q1;
for (int i=0;i<count;i++)
{
q1->get_cho()[i].set_type(temper);
cout<<"Please enter the text for Choice " <<i+1<<":" ;
getline(cin,temp);
cout<<q1->get_cho()+i<<endl;
choic[i].set_answer(temp);////////////////crashes here for i>0
cout<<"aaaa*" <<endl;
// cout<<q1->get_cho()[i].get_answer();
//cout<<&q1->get_cho()[0]<<endl;
//cout<<&q1->get_cho()[1]<<endl;
}
}
else if (temper==2)
{
Choices* choic=new CheckBoxes[count];
q1->set_cho(choic);
// sur.questions[i][0].
q1->get_cho()->set_type(temper);
//cout<<q1->get_cho()->get_type();
q1->set_choices(count);
sur.questions[i]=*q1;
for (int i=0;i<count;i++)
{
cout<<"Please enter the text for Choice " <<i+1<<":" ;
getline(cin,temp);
q1->get_cho()[i].set_answer(temp);///////////crashes here for i>0
}
}
Last edited on Sep 12, 2013 at 2:09pm Sep 12, 2013 at 2:09pm UTC