I'm creating a program in which user enter mcqs and option and then save the data into the txt file.How can i do this .I try but it's not working.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream outputFile;
std::string fname;
cout<<"Enter file name";
std::getline (std::cin,fname);
outputFile.open(fname+".txt");
std::string name;
std::string mcqs;
int x;
cout<<"How many questions want \n";
cin>>x;
for(int i=1;i<=x;i=i+1){
cout<"Enter question "+i;
std::getline (std::cin,name);
outputFile << name << endl;
cout<<"Option A";
std::getline (std::cin,mcqs);
outputFile << mcqs << endl;
cout<<"Option B";
std::getline (std::cin,mcqs);
outputFile << mcqs << endl;
cout<<"Option C";
std::getline (std::cin,mcqs);
outputFile << mcqs << endl;
cout<<"Option D";
std::getline (std::cin,mcqs);
outputFile << mcqs << endl;
}
outputFile.close();
cout << "Done!\n";
getchar();
return 0;
}
I want save mcqs and option in txt file.Thanks
Aucun commentaire:
Enregistrer un commentaire