I'm helping a friend out with some code and I'm having the hardest time figuring out how to do this. I know it is simple, but for the life of me I can't remember how to do it. Any help or advice would be welcomed. Thanks for the help in advance.
Problem: I need to open a file first, then have a user input a 6 digit number then check the file and if it finds it then it will get the name by it and if it doesn't exist in the file then it will say so. I'm having trouble having it run through and check the file. I can have it run through the whole document and output the data and I can check the very first line of data, but after that I can't get it to work at all. It will get the first three data values from the file if it isn't the first number of the file, but it won't get the name or check. I haven't got to the part about output if the number doesn't exit in the file, but I'm not concerned about that part yet. Here is my code. Thanks again for the help.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std; //helps run the program
int main()
{
double sticker;
string Fname;
double first;
string second;
second = "not";
ifstream dataIn; //for the data input
dataIn.open("HWK5.txt");
cout << "sticker: ";
cin >> sticker;
while(dataIn)
{
dataIn >> first;
cout << first << endl;;
if (first == sticker)
{
dataIn >> second;
cout << second << endl;
Fname = second;
}
else if (first != sticker){
dataIn >> first;
cout << first << endl; }
}
cout << "here: " << Fname << endl;
dataIn.close();
system("Pause");
return 0;
}
/*
while(dataIn)
{
dataIn >> first;
cout << first << endl;
if (first != sticker){
dataIn >> first;
cout << first << endl; }
else if (first == sticker)
{
dataIn >> second;
cout << second << endl;
Fname = second;
}
}
*/
Sincerely yours;
jdm