Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ifstream

Status
Not open for further replies.

cweb255

Programmer
Nov 21, 2003
1
US
Sorry, I know I'm very new at this, but I'm also very interested. Here's what I got so far:
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct EmpInfo
{
string fname;
string mname;
string lname;
string SSN;
string hours;
string rate;
string CurrentEvalNum;
string dept;
string exempt;
};

int main()
{
genesis:
string choice;
cout << &quot;Type \'add\' to add an employee&quot;;
cout << &quot;, type \'find\' to look-up an employee&quot;;
cout << &quot;, or type \'exit\' to exit: &quot;;
cin >> choice;
if ( choice == &quot;a[0]&quot;||&quot;A[0]&quot;)
{
EmpInfo ei;
ofstream myFile(&quot;C:/Windows/Desktop/employees.txt&quot;, ios::eek:ut | ios::app);
cout << &quot;First Name: &quot;;
cin >> ei.fname;
myFile << &quot;ei.fname| &quot; << ei.fname << endl;
cout << &quot;Middle Name: &quot;;
cin >> ei.mname;
myFile << &quot;ei.mname| &quot; << ei.mname << endl;
cout << &quot;Last Name: &quot;;
cin >> ei.lname;
myFile << &quot;ei.lname| &quot; << ei.lname << endl;
cout << &quot;Social Security Number: &quot;;
cin >> ei.SSN;
myFile << &quot;ei.SSN| &quot; << ei.SSN << endl;
cout << &quot;Rate: &quot;;
cin >> ei.rate;
myFile << &quot;ei.rate| &quot; << ei.rate << endl;
cout << &quot;Current Evaluation (in number): &quot;;
cin >> ei.CurrentEvalNum;
myFile << &quot;ei.CurrentEvalNum| &quot; << ei.CurrentEvalNum << endl;
cout << &quot;Department: &quot;;
cin >> ei.dept;
myFile << &quot;ei.dept| &quot; << ei.dept << endl;
cout << &quot;Is &quot; << ei.fname << &quot; &quot; << ei.lname << &quot; exempt? \'y\' or \'n\': &quot;;
cin >> ei.exempt;
myFile << &quot;ei.exempt| &quot; << ei.exempt << endl << endl;

myFile.close();
}

else if (choice == &quot;f[0]&quot; || &quot;F[0]&quot;)
{
string searched;
cin >> searched;
if (searched == &quot;fname&quot; || &quot;FNAME&quot;)
{

}
if (searched == &quot;lname&quot; || &quot;LNAME&quot;)
{

}
if (searched == &quot;SSN&quot; || &quot;ssn&quot;)
{

}
}
goto genesis;
else if (choice == &quot;e[0]&quot; || &quot;E[0]&quot;)
{
break;
}
}

My question is that how would I instead of just ammending to the file to be able to edit it also via arrays. All the output in employees.txt are saved like &quot;ei.fname| Chris&quot; Thanks in advance! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top