Witam, mam problem otóż program wysypuje się przy 33 powtórzeniu pętli while(getline(f1,l)). Jako błąd debbuger pokazuję Program received signal SIGSEGV, Segmentation fault. In std::string::assign(std::string const&) () oraz Nie można odnaleźć lub otworzyć pliku PDB. Macie jakieś sugestię?
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
string Q[5];
string A[5],B[5],C[5],D[5];
string CA[5];
fstream f1;
string l;
string topic,author;
string answer;
int nr_l=1;
int nr_q=0;
int points=0;
f1.open("Quiz.txt",ios::in);
if(f1.good()==false)
{
cout<<"The file does not exist"<<endl;
exit(0);
}
while(getline(f1,l))
{
switch(nr_l)
{
case 1: topic=l; break;
case 2: author=l; break;
case 3: Q[nr_q]=l; break;
case 4: A[nr_q]=l; break;
case 5: B[nr_q]=l; break;
case 6: C[nr_q]=l; break;
case 7: D[nr_q]=l; break;
case 8: CA[nr_q]=l; break;
}
if(nr_l==8)
{
nr_l=2;
nr_q++;
}
nr_l++;
}
f1.close();
cout<<"The topic of the quiz is: "<<topic<<endl;
cout<<"The author of a quiz is: "<<author<<"\n\n"<<endl;
for(int i=0;i<=4;i++)
{
cout<<Q[i]<<endl;
cout<<"A. "<<A[i]<<endl;
cout<<"B. "<<B[i]<<endl;
cout<<"C. "<<C[i]<<endl;
cout<<"D. "<<D[i]<<endl;
cout<<"Your Answer is: ";
cin>>answer;
transform(answer.begin(),answer.end(),answer.begin(), ::tolower);
if(answer==CA[i])
{
cout<<"\n"<<"Correct answer.You earned 1 point."<<endl;
points++;
}
else cout<<"Wrong answer.The correct answer is "<<CA[i]<<endl;
}
cout<<"A quiz has been finished. You earned "<<points<<" Congratulations!"<<endl;
return 0;
}