0

I want to read in multiple lines from a file, but I am only able to get my program to read the first line. The program prints out two other lines but the values are zero.

double cost[3];
	int lowerRange[3];
	int higherRange[3];
	bool active[3];
	ifstream inClientFile("ad.txt", ios::in);
	for (int i=0; i<3; i++) {
	(inClientFile>>cost[i]>>lowerRange[i]>>higherRange[i]>>active[i]);
		Ad ad(cost[i], lowerRange[i], higherRange[i], active[i]);
cout << ad.getCost()<<" "<<ad.getRangeLower()<<" "<<ad.getRangeHigher()
<<" "<<ad.getState()<<endl;

What I am trying to do is get the file to read in four values, send them to the constructor and then prints them out. Any help is appreciated

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by jonsca
0

I am trying to have this read into the constructor

24.98 25 50 True
32.43 30 60 False
42.75 50 70 True

0

Dont know if this is your original code but there's no closing curly brace at the end of the for loop

0

included the curly bracket in my program forgot to put when I posted it

0

It's choking on reading the true or false values. When reading a bool from a file it's looking for a 0 or (EDIT: only works for 1) a 1 as false and true.

Read in "true" or "false" from your file as a string and then convert it to boolean true or boolean false.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.