So I'am trying to make a program that uses a while loop to pull data form a text file.
I'm using a while loop because I do not know how many times it will have to loop, and as for as I know for loops are only useful for when you know how many times you want to loop.
I want my program to read to gather input from a txt file, and loop until there is an empty space.
I need help setting my condition to stop when there is an empty space.
For example:
The input file:
55
77
88
55
while( there is a value continue, when there is no value break loop)
Your code is all nonsense. You're treating line as if it were a complex object, and it isn't. I think you are blurring two different concepts here.
First of all, your boolean value would not represent the line, so "line" is a poor name. Remember a boolean can only be either true or false. There is no "empty" function that can be used for booleans. It's impossible for a boolean to be empty.
The boolean would represent whether or not you found an empty line.
For the actual line, you would need another variable (probably a string).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bool empty_line_found = false;
string line;
while(!empty_line_found)
{
// get the line from the file here, put it in 'line'
if( /*is 'line' an empty string?*/ )
{
// if yes, we found an empty line, so set our flag to 'true'
empty_line_found = true;
}
else
{
// otherwise, we have a line with data in it.
// process the data here
// (ie: do whatever you're supposed to be doing with these lines as you read them)
}
}