FILE reading. How to?

I'm currently attempting to read a file from my resource area in visual studios. I am unsure as to how to even begin to enter the file and access the data within. The file contains a student's first and last name, their student ID number, what they are majoring in and which grade they're in. Any ideas?
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/doc/tutorial/files/
OP: you need to set up a struct for a student, something like:
1
2
3
4
5
6
7
8
struct Student
{
	string first_name;
	string last_name;
	double ID;//assuming ID is numeric only, else string
	string major;
	string double;//again can be int be grade is (small) numeric
}


Then you need to read data from the file into Student objects arranged in an array: see this example - http://www.cplusplus.com/forum/beginner/203673/
Note: if you're reading the file into an array you'd need to know and tell the program by run-time how many objects (i.e students) there are in the file. Alternatively you can use std::vector that does its own memory anagement and so you don't need to tell anything how many objects you're going to read in.
Anyways I suggest you get started with kemort's link and start arranging your program and then come back here if you face any hurdles or want to use vectors. Good luck!
Topic archived. No new replies allowed.