Jul 8, 2018 at 2:53am UTC
I am working on a program that saves various account names in a file, which have been created, and then access them in the same file. The problem that I'm having is that I'm not sure how to look for a specific passcode (string) in the file.
For example, the program asks for my account which I have created, and I enter it in, where it has to find it in the whole file.
Case B deals with searching for a file in memory.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
char choice;
int id;
string lstname, fstname, passcode;
cout << "Main Menu." << endl;
cout << "A.Create New Account" << endl;
cout << "B.My Account" << endl;
cout << "C.Exit" << endl;
cin >> choice;
switch (choice)
{
case 'A':
{
{
int yesorno;
int i = 0;
i++;
do{
cout << "Create your account id: ";
cin >> id;
cout << "First name: ";
cin >> fstname;
cout << "Last name: ";
cin >> lstname;
cout << "Create passcode: ";
cin >> passcode;
ofstream outStream;
outStream.open("accountstorage.txt", ios::app);
if (outStream.fail())
{
cout << "File failed.";
exit(0);
}
//getline (cin, fstname);
//getline (cin, lstname);
outStream << id << " " << lstname << ", " << fstname << " " << "***PASSCODE*** " << passcode << endl;
cout << "Enter in more accounts?" << endl;
cout << "Answer with 1 for Yes and 2 for No." << endl;
cin >> yesorno;
if ((yesorno == 2))
{
exit(0);
}
if ((yesorno == 1))
{
cout << " ";
}
else
{
exit(0);
}
outStream.close();
}while (i<99999);
}
}
break;
case 'B':
{
vector<string> passcode2;
//string passcode[99];
int id[99];
ifstream inStream;
inStream.open("accountstorage.txt");
string targetcode;
cout << "Enter your passcode. " << endl;
//getline(cin, targetcode);
cin >> targetcode;
cout << passcode2.size();
for (int i=0; i<passcode2.size(); i++)
{
cout << "something";
if (passcode2[i] == targetcode)
{
cout << "Account found. " << endl;
cout << "id: " << id[i] << endl;
cout << "Name: " << fstname << " " << lstname << endl;
}
else
{
cout << "Account not on record." << endl;
}
}
}
break;
case 'C':
{exit(0);}
break;
default:
{cout << "Not a possible choice.";
exit(0);}
}
return 0;
}