So I'm relatively new to C++ and coding and I recently tried to make this survey program (Please ignore the horrible code). Where I'm stuck is the fact that at the end, when the user would ask for existing info, I have no way to find that particular info with the name in the text file. What can I do about it? Also, the goto label before ExisitingUser shows something like -fpermissive error. Don't know what that is.
Apologies if something like this has been answered before. Couldn't find it.
The code:
#include<iostream> #include<fstream> #include<string> using namespace std; int main() { char choiceInfo; cout << "Do you want to enter a new user or check existing info? N/E\n"; cin >> choiceInfo; if(choiceInfo == 'N' || choiceInfo == 'n') { } else { goto existUser; } x: string firstName,surName,fullName,DoB,quesOne,quesTwo,quesThree,quesFour,quesFive; int age; cout << "Enter your first name.\n"; cin >> firstName; cout <<"Enter your surname.\n"; cin >> surName; fullName = firstName + surName; cout << "How old are you?\n"; cin >> age; cout << "What is your DoB?\n Format:DD/MM/YYYY\n"; cin >> DoB; cout <<"What is your favorite sport?\n"; cin >> quesOne; cout <<"What is your favorite colour?\n"; cin >> quesTwo; cout <<"Who is your favorite celebrity?\n Please enter all in one word.\n"; cin >> quesThree; cout <<"What is your favorite hobby?\n"; cin >> quesFour; cout <<"Which is your favorite quote?\n"; cin >> quesFive; cout << "Thank you for registering."; ofstream writer("Users.txt"); writer << endl << endl << endl << "Full Name: " << fullName << endl << "Age: " << age << endl << "DOB: " << DoB << endl << "Answer to Question 1: " << quesOne<< endl << "Answer to Question 2: " << quesTwo << endl << "Answer to Question 3: " << quesThree << endl << "Answer to Question 4: " << quesFour << endl << "Answer to Question 5: " << quesFive << endl; writer.close(); goto z; existUser: { string userName; char letter; cout << "Enter full username.\n"; cin >> userName; ifstream reader("Users.txt"); if (! reader) { cout << "Error opening file."; } else { char(letter); for (int i = 0;! reader.eof(); i++) { reader.get(letter); cout << letter; reader.close(); } } } z: return 0; }