So I have a few questions, just trying to get my head around this file business:
- Is there a more direct way to assign the data from the file to the new object (ie. omit the need for Data[][])?
- I've created an array of three objects in this program. What happens if I want to delete pItem[1] and keep the rest?
- If I need specific data for Item "Pencil", which is hypothetically located at line XXX of items.txt, how do I grab that data and ignore the rest?
- In general, should I be opening/closing the files in any way other than how I am now? I've see while(!fItems.eof()) used a lot, so.
Super low-level questions here I'm guessing, this is my first shot at doing this. Thanks in advance guys.
- I've created an array of three objects in this program. What happens if I want to delete pItem[1] and keep the rest?
Use vectors, not arrays.
- If I need specific data for Item "Pencil", which is hypothetically located at line XXX of items.txt, how do I grab that data and ignore the rest?
Unless you've already read through the entire file at one point and cached the byte offsets of the beginning of each line, there is no way to jump to a specific line. You will have to read the file line by line (e.g. with while(getline(file, line)))
- In general, should I be opening/closing the files in any way other than how I am now?
Yes. Remove that fItems.close(); unless you have something special to do if close() fails. Files are unconditionally closed when they leave scope.
With proper file input, the is_open() check is not needed either, unless you have a non-empty "else" clause (which you don't).