data parse

please help!
Inside of my project I need to get data from file and put in in array.here is file ->
D306 Capacity 32

1 1 3 5
2
3
4 2 4 5
5 1 2
6 2 5
7 1 2 4

I must take class name (D306), capacity and (32)
here is what I wrote.





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
34
35
36
37
38
39


#include"Classroom.h"

Classroom::Classroom(){

	name = "";


}


void Classroom::initializeClass(string name){

	fstream f;

	this->name = name;

	f.open(name,ios::in);

	if (!f)
	{
		cout<<"File could not be opened"<<endl;
	}
	//read first line, assign capacity
	string firstline;
	getline(f,firstline);


	
	string lines;
	
	while (getline(f,lines))
	{
		//read lines with getline
		//parse all lines according to \t or ' ' with stringstream
		//When you parse, assign these values to data members of the objct (name, capacity, schedule)
	}
}
I must take class name (D306), capacity and (32)

no idea what this means and, more importantly, how is the text file organized vis-a-vis the layout of the class? What is the relationship b/w lines of the file and data-members of the class?
Not sure about what you meant over there but it looks like your stream escapes from your scope by calling getline() over there. These kind of things affects errors a lot of times and I recommend you to try and no to do it. Those kind of errors are hard to detect most times, unless you use programs like checkmarx or others of course. But in case you don't it's very recommended to try and avoid it. Maybe other design would help.
Good luck with it!
Ben.
Topic archived. No new replies allowed.