How to Search For a Word and Display Line Containing that Word and Specific # Lines After

I am STUCK! I have searched and searched and searched through every example and I can not find anything that has helped me! I'm using Dev-C++. The program that I am trying to write is broken down into sections. The user will choose an option from a menu and lead the user to that particular section. I am completely stuck on option 2 and 3 (I am working by section and saving the hardest for last lol!). So for section 3, I need the user to enter a Job #, have the program search my file for that job number, and display the line that contains that job number, and the seven lines that follow that job number. For option 2 I need to be able to update a particular job multiple times as it progresses through our processes, but I will repost that when I finish option 3 (easy does it mister lol!). Any help is greatly appreciated! Blow is my code, and a sample of what my file will look like.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
int menuoption;
string jobnumber;
string account;
string description;
char me;
string findnumber;
char c;
ofstream myfile;
ifstream ourfile;
cout<<"JM Designs \n\n";
cout<<"Please choose from the following options.\n\n";
cout<<" 1. Enter New Job Information. \n\n";
cout<<" 2. Update Existing Job Information. \n\n";
cout<<" 3. Display Job Information. \n\n";
cout<<" 4. Display Report. \n\n";
cout<<" 5. Exit. \n\n";
cin>>menuoption;
if (menuoption == 1)
{
myfile.open("jobs.txt", ios::app);
if( myfile.is_open())
{
myfile.seekp(ios_base::end);
}

cout<<"Enter Job Number : ";
cin>>jobnumber;
cout<<"\n";
myfile<<"Job #"<<jobnumber<<endl;
cout<<"Enter Account : ";
cin.ignore();
getline(cin, account);
cout<<"\n";
myfile<<"Account : "<<account<<endl;
cout<<"Enter Description : ";
getline(cin, description);
myfile<<"Description : "<<description<<endl;
myfile<<"Wax : "<<endl;
myfile<<"Cast : "<<endl;
myfile<<"Clean Up : "<<endl;
myfile<<"Set : "<<endl;
myfile<<"Completed : "<<endl;
myfile<<"\n";
myfile.close();
}
else if (menuoption == 2)
{

cout<<"Enter Job Number You Wish to Update : ";
cin>>findnumber;
cout<<"\n";

}
else if (menuoption == 3)
{
ourfile.open("jobs.txt");
cout<<"Enter Job Number You Wish to View : ";
cin>>jobnumber;

if (jobnumber != "\n")
{
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
getline(ourfile,jobnumber);
cout<<jobnumber<<endl;
cout<<"\n";
}
ourfile.close();
system("PAUSE");
}
else if (menuoption == 4)
{

ourfile.open("jobs.txt", ios::in);
ourfile.get(c);
while(!ourfile.fail() && !ourfile.eof())
{
cout << c;
ourfile.get(c);
}
ourfile.close();
system("PAUSE");
}

else if (menuoption == 5)
{
cout<<"Are You Sure You Would Like to Exit? (Y or N) : ";
cin>>me;
}
else
{
cout<<"You Have Entered A Wrong Command, Please Try Again ";
}
cout<<"Have A Great Day!";





return 0;
}


Excerpt of my File

Job #30326
Account : JMD
Description : Lady's Platinum Band
Wax :
Cast :
Clean Up :
Set :
Completed :

Job #30327
Account : Union
Description : Gents Gold Ring
Wax :
Cast :
Clean Up :
Set :
Completed :

Job #30328
Account : Dynasty
Description : Various Repairs
Wax :
Cast :
Clean Up :
Set :
Completed :

Job #30329
Account : Union
Description : 18KT White Gold Diamond Band
Wax :
Cast :
Clean Up :
Set :
Completed :

Don't know if I can help you, but you might want to copy and paste the code using the <> format first.
Do I just put the code in < code >?
Throw the code in between [code] [/ code]

Remove the spacing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <fstream>
#include <string>
 
using namespace std;
 
int main()
{
    int menuoption;
    string jobnumber;
    string account;
    string description;
    char me;
    string findnumber;
    char c;
    ofstream myfile;
    ifstream ourfile;

  cout<<"JM Designs \n\n";
  cout<<"Please choose from the following options.\n\n";
  cout<<" 1. Enter New Job Information. \n\n";
  cout<<" 2. Update Existing Job Information. \n\n";
  cout<<" 3. Display Job Information. \n\n";
  cout<<" 4. Display Report. \n\n";
  cout<<" 5. Exit. \n\n";
  cin>>menuoption;
  if (menuoption == 1)
     {
                 myfile.open("jobs.txt", ios::app);
                 if( myfile.is_open())
                     {
                         myfile.seekp(ios_base::end);
                     }

                 cout<<"Enter Job Number : ";
                 cin>>jobnumber;
                 cout<<"\n";
                 myfile<<"Job #"<<jobnumber<<endl;
                 cout<<"Enter Account : ";
                 cin.ignore();
                 getline(cin, account);
                 cout<<"\n";
                 myfile<<"Account : "<<account<<endl;
                 cout<<"Enter Description : ";
                 getline(cin, description);
                 myfile<<"Description : "<<description<<endl;
                 myfile<<"Wax : "<<endl;
                 myfile<<"Cast : "<<endl;
                 myfile<<"Clean Up : "<<endl;
                 myfile<<"Set : "<<endl;
                 myfile<<"Completed : "<<endl;
                 myfile<<"\n";
                 myfile.close();
     }
         else if (menuoption == 2)
              {

                 cout<<"Enter Job Number You Wish to Update : ";
                 cin>>findnumber;
                 cout<<"\n";
                                  
              }
         else if (menuoption == 3)
              {
                 ourfile.open("jobs.txt");
                 cout<<"Enter Job Number You Wish to View : ";
                 cin>>jobnumber;
                 if (jobnumber != "\n")
                    {
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        getline(ourfile,jobnumber);
                        cout<<jobnumber<<endl;
                        cout<<"\n";                        
                        }
                ourfile.close();
                system("PAUSE");
              }
         else if (menuoption == 4)
              {

                 ourfile.open("jobs.txt", ios::in);
                 ourfile.get(c);
                 while(!ourfile.fail() && !ourfile.eof())
                   {
                       cout << c;
                       ourfile.get(c);
                   }
                 ourfile.close();
                 system("PAUSE");
               }

         else if (menuoption == 5)
              {
                 cout<<"Are You Sure You Would Like to Exit? (Y or N) : ";
                 cin>>me;
              }
         else
              {
                 cout<<"You Have Entered A Wrong Command, Please Try Again ";
              }
              cout<<"Have A Great Day!";
                 
  
  
  
  
return 0;
}       
 
Topic archived. No new replies allowed.