I am finally learning about fstream but Im stomped with this problem that I have. I have a current file that I am opening. Each line of said file looks like this:
D40001~10997~811~DANIWEB~555-555-5555~7.70~I~2111
There are around 5000 lines with different DXXXXX numbers. I want the user to input a dnumber (DXXXXX) and have it search the file for said Dnumber and then display the name that is associated with the Dnumber. So typing in 'D40001' should display the name Daniweb. Here is my code but I've went through 5 tutorials on the net and cannot find out how to search this file and do what I want it to do. From the searching that I did do, they said that I need to parse the file and then match the DXXXXX and display the screen. I'm clueless to how to do this. Here is the code that I have so far. Also, this is not for homework. I'm too poor for school. :]
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
void Display();
void SearchNumber(string);
int main()
{
// Variable for the dealer number
string dNumber;
// ofstream constructor opens file
ifstream dealers ( "dealers.tdl", std::ios::in);
// exit program if unable to open file.
if (!dealers)
{
cerr << "File could not be opened" << endl;
exit(1);
}
Display();
cout << "D Number: ";
cin >> dNumber;
}
// Puts the D Number request in the middle of the Dos Window
void Display()
{
for (int i = 0; i < 11; i++)
cout << endl;
for (int j = 0; j < 33; j++)
cout << " ";
}