Hello rhap123,
First you have not shown what the input file looks like, so I can not even begin to know if you are reading the file correctly.
Second you have not explained what the program should do. If you expect people to guess at what you need to do, do not expect much response.
When you post code it is best to post a complete program that can be compiled and run.
You are not reading the file stream that you opened, but a totally different file stream that is not even defined.
All your code does is produce errors. Some errors are from variables that are not defined.
The while loop will most likely be bypassed most of the time because of the return value of ".empty()".
The statement
else if (name == name)
You are comparing the same variable to its-self, so it will always be true. Also in this else if you are opening the file stream and closing at the end of the block. The "close()" is not needed because the closing ( } ) of the block will close the file when it loosed scope.
Your 2 sections of code print to the screen before you read the file and have given the variables something to print.
Some of this may be called "old school", but that is what I first learned.
Define variables.
Open file stream
You can use
|
std::ifstream inFile("test.txt"); // <--- This defines the file stream and opens the stream at the same time, or when the object is constructed.
|
Check that the file opened:
1 2 3 4 5 6
|
if (!inFile)
{
std::cout<<"\n File \"test.txt\" did not open!\n";
return 1;
}
|
Read file
Process what is read
When I have more to work with I will have a better idea what you need to do.
For now I would work on opening the file and reading 1 record then print that to the screen. once that part is working you can expand the program.
Andy