Ugh, help. Easy I think?

Below I have a .txt file that I have to make into a program that displays the following as an output..

Name (First M Last):
Test Averages:
Grade:
Absences:

How do I make it so the .txt file is converted into that format?

Sorry if you don't understand my question..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Wiley, Nicholas I.,9,23,97,0
Schwarz, Larry C.,64,18,47,0
Grimes, Linda R.,17,53,43,2
Brown, Ronald R.,53,63,85,1
Hines, Neil I.,3,49,68,0
Jain, David A.,92,85,83,1
Glass, Cindy L.,68,69,54,4
Fowler, Jacob O.,82,91,40,3
Schneider, Wanda C.,58,51,37,0
Gilbert, Edith I.,39,99,34,0
Parker, Nicole A.,60,88,44,0
Shaw, Cecil H.,37,9,19,0
Gold, Caroline O.,1,41,48,0
Monroe, John O.,64,6,12,2
McDowell, Steve C.,56,79,25,1
Sumner, William U.,59,51,98,3
Pugh, Francis U.,32,65,53,2
Crane, Gary R.,62,39,13,2
Stevens, Eleanor T.,7,42,82,0
Greer, Anne R.,5,54,20,0
McKay, Dana C.,30,86,21,0
Crawford, Pauline R.,49,21,9,1
Stephenson, James T.,19,92,63,1
Stark, Peter T.,27,43,98,1
Rodgers, Lucille O.,94,57,86,0
Read the text file in line by line as a string. Then you will be able to use each string to search through the string to pull out what you need. For example:

.txt
1
2
3
Wiley, Nicholas I.,9,23,97,0
Schwarz, Larry C.,64,18,47,0
...


string 1 =
Wiley, Nicholas I.,9,23,97,0


so from the start till ".," would be the name.

Does this help?
So I would have to make a new string for each line of data? An example would be much appreciated
Exactly. Unless it is for one time use only. I will work on an example in a moment.
Thank you!
Okay this is an example that I whipped up, I hope this helps. It worked on my end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include <iostream>
#include <string>
#include "AP_String_Helper.h"
#include "AP_File_Handler.h"
using namespace std;


int main()
{

	AP_String_Helper help; //for string parsing 
	AP_File_Handler file; //for file i/o
	file.set_file_name("students.txt"); //the file name

	for(int i=0; i<file.return_size(); i++){ //for each student in file

	string student; //used to store student details
	student=file.read_next_line(); //gets the line from the file
	int place;


	place=help.find_next(".,",0,student); 
	cout<<"Name: "<<help.from_to(student,0,place)<<endl; //gets and displays the name

	cout<<"Test grades: "<<help.from_to(student,place,student.size())<<endl; //grade...ect

	
	}

    return 0;
}
I get this when I try to run that

fatal error C1083: Cannot open include file: 'AP_String_Helper.h': No such file or directory
You need to add "AP_String_Helper.h" and "AP_File_Handler.h" to your project. You also get those files from http://www.binary-thoughts.net/aplibrary.php
If you need help on that process I can help you do that as well.
Is there a way I can do this without that? I'm trying to work on an assignment and we never had those options in class.
Yeah, the idea is the same. You just have to make all the functions yourself.
In most cases teachers will allow external libraries though. I would check with your teacher. Its the same as using STL or Boost. Building from scratch is almost a thing of the past.
Yeah my teacher is pretty old school I guess then, we are required to do it from scratch I think. Can you link me to example of the kind of function I'd need to make then?
Here is the only function I really use besides the file I/O

1
2
string from_to(string a_string,int start, int stop); // returns a string form the beginning of "a_string" up to "stop".


It returns a part of a string by start and stop for example:

1
2
3
4
string str="this string";

str = from_to(str, 0, 3);
//str would be "this" 

make sense?
Last edited on
Topic archived. No new replies allowed.