read file and put into struct

Hello guys
I got some weird result,
I want to read this txt file
------------------------------
1001 0 10 2
1002 2 7 3
1003 5 12 4
1004 6 9 2
------------------------------
this program is to model the FCFS process model
any way i tried to read those file and put in struct

1
2
3
4
5
6
7
8
9
struct sys_info{
	int id;
	int arrival_time;
	int total_cpu;
    int average_cpu_burst;



};


and read file

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
int main(){
	vector<int> haha;
	int inti,clock;
	info in;
	clock =0;
	vector<sys_info> running;
	vector<sys_info> arrival;
	vector<sys_info> ready;
	vector<sys_info> waiting;
	ifstream ifs("file.txt");

	

	if(!ifs) {cout << "could not open the file"; exit(1);

		}else{
			
		while(ifs>>inti){
		
		//cout << inti <<" ";
		sys_info temp;
		
		cout << inti <<endl;
		temp.id = inti;
		ifs>>inti;
		cout << inti <<endl;
		temp.arrival_time = inti;
		ifs>>inti;
		cout << inti <<endl;
		temp.total_cpu = inti;
		ifs>>inti;
		cout << inti <<endl;
		temp.arrival_time = inti;
		
		arrival.push_back(temp);

		
		}
		

	}
	
	 for(int i=0 ; i < arrival.size() ; i++){

		 print_cpu_info(arrival[i]);
	 }

	cout <<  "==============" << endl;
	cout <<  "    FCFS      " << endl;
	cout <<  "==============" << endl;

	
	
	
	//void print(int time, string running,string arrival,int rp ,string ready,string waiting,int t1,int remain)
	//print(in.time,in.running,in.arrival,in.rp,in.ready,in.waiting,in.t1,in.remain);
	//print(clock,running,arrival,ready,waiting);
	//runningFunc(running,arrival,ready,waiting,in,clock);
	

}

1
2
3
4
void print_cpu_info(sys_info & cpu){

	cout << "cpu: " <<cpu.id << " arrival time "<< cpu.arrival_time << "total cpu "<< cpu.total_cpu << "cpu burst " << cpu.average_cpu_burst<<endl; 
}



cpu: 1001 arrival time 2 total cpu 10 cpu burst -858993460
cpu: 1002 arrival time 3 total cpu 7 cpu burst -858993460
cpu: 1003 arrival time 4 total cpu 12 cpu burst -858993460
cpu: 1004 arrival time 2 total cpu 9 cpu burst -858993460



And which line of code in the above do you think is storing a value in average_cpu_burst?

There isn't one.
Last edited on
Topic archived. No new replies allowed.