File Output:

#include <iostream>
#include <fstream>
using namespace std;

char finit;
char linit;

int main(void)
{
   fstream myfile;

   cout << "First Initial? ";
   cin >> finit;
   cout << "Last Initial? ";
   cin >> linit;

   myfile.open("xyz.dat", ios::out | ios::app);
   myfile << finit << "|";
   myfile << linit << endl;
   myfile.close();

   return 0;
}


File Input:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string line;

int main(void)
{
   fstream myfile;

   myfile.open("xyz.dat", ios::in);

   getline(myfile, line, '\n');

   while ( !myfile.eof() ) {
      cout << line << endl;
      getline(myfile, line, '\n');
   }

   myfile.close();
   return 0;
}


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string line;
int pipeloc;
string finit;
string linit;

int main(void)
{
   fstream myfilehandle;

   myfilehandle.open("xyz.dat", ios::in);

   getline(myfilehandle, line, '\n');

   while ( !myfilehandle.eof() ) {
      pipeloc = line.find("|");
      cout << "The seperator is at " << pipeloc << endl;
      finit = line.substr(0,pipeloc);
      cout << "The first initial is " << finit << endl;
      getline(myfilehandle, line, '\n');
   }

   myfilehandle.close();
   return 0;
}