Hi, I am trying to write a program for uni that will read two different .txt files and output some data about them. I am fairly confident I can do this I just cant figure out what arguments to pass to my functions to read the files properly?
students.txt is a long file, with one word on each line. If someone can point me in the right direction on how to properly pass the correct arguments across I am confident I can right the code in the functions to output the data.
students.txt example:
1 //number of entrys
Sarah
Jones
1111
y
The typical way is to call something like getline in a loop to read from the ifstream and store the result into an array. It's up to u. The way u'r going u'll have to create a bunch of Student instances and pass each one into readStudents which could take a lot for memory.
Line 26 doesn't make sense because u'r passing a structure and not an instance of it. This makes more sense, for example:
thanks for the reply, that newstudent does make a lot more sense but would that run through my for loop to however many students was in the .txt? or would I have to create more instances like newstudent1 etc? (which would kind of defeat the purpose of the loop) lol. I think I am just a little confused on where they are supposed to get stored, if they should even get stored?
I am only supposed to read the file once and yeah I think I would have used a getline but we are not supposed to use functions that we have not yet covered. Just so annoying I cant even try and write the rest of the code because its not even reading the .txt in
Never mind all the above code, I have spent hours re writing and re re writing my program.. Good news is that I have made much progress and it looks completely different.
Is there any way I can read from a .txt file until I reach a certain character? I want to read the top 3 lines but after that there could be unknown amount of lines (if any) until the -1.
hey man
how did you sloved it in fact i m struggling with it
its first time i have use structures and i dont know which argu for both student and course function should i pass in order to read and out put some information
like if i wanna output the student info for who have N in thire record
i thought mine was solved but its not... I'm having problems storing the info. I want to store certain lines from the txt into an array so I can access the info later but just cant figure out how to do this..
Can someone please tell me why I can't get the studentsAll[i].id to store its values in the array list? I've tried for hours and have run out of ideas.
What is happening or being stored into studentsAll[i].id instead ?
line 2 extracts into studentsAll[i].id
but then line 3 is storing whatever is in studentsAll[i].list into studentsAll[i].idagain. is this desired? what is being stored into studentsAll[i].list ?
Sorry i typed that out the wrong way.. line 2 is reading in 4 lines of a txt file, then i want to put what studentsAll[i].id reads into an array or a list of arrays so i can re read them later?
line 3 was supposed to read
studentsAll[i].list = studentsAll[i].id
but when I compile the prog I just get 3 empty spaces where I try and output the list to make sure I have stored them correctly.
Here's a nice way to organize your data. Encapsulation and safety is always good. It also promotes organization, so you'd have to go out of your way to get lost.
Thanks for the help my codes changed quite a lot, find it hard to get the private and public and what's available around my head. ^It looks a bit confusing but I think its similar to what I have, but i'm still very confused on how to actually store values so they can be accessed later? Here is my whole program
So I am reading the students text, but I want to save all the student.ids I read in to access them later on in the program without re reading the file.