im making a program where i have a txt file that has names of student

basically i have to pull out those names using c++ strings and set them in alphabetical order.

for that i will be using a while loop that will read the students and update as to who is first and who is last.

it should keep a count of how many students there are and use:

while (infile >> studentName) {loop body}

these are the c++ string variables that i will be using:
string fileName;
string studentName;
string firstStudent;
string lastStudent;

these are my instructions for my assignment, but im a bit shaky on file i/o (ive only done it once) i just need to know how should i approach this! this is kinda new for me~

any help would be great guys!!
thanks so much!!! you guys are lifesavers!!!

you could do something like this, assuming you don't need to keep all the names in memory at the same time

int count = 0;
infil >> firstStudent;
while( infile >> lastStudent)
   count++;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.