Hello helpwithcplusplus,
Starting at the top some tips. Between the first line and main a couple of blank lines would be nice. Or even remove line 4 and leave it a blank line.
Inside main:
"Declare variables" you do not need two "ifstream"s just one. And the ofstream is not used right now. OK to leave it if you have a future use for it.
Lines 17 - 19 are not needed. Lines 17 and 18 are reading a file stream only once and then never used.
Line 23 is the while loop yu should use and better written as:
1 2
|
while (fin >> flowerName >> sun_or_shade)
cout << flowerName << " grows in the " << sun_or_shade << endl;
| |
The problem you are having with no output is that you are trying to use "data_in" which was never opened. Only "fin" was opened, so you are trying to read a file stream that does not exist.
Once I made those changes it ran fine, And there is no need to change the input file it works fine.
The only thing I can think of that might be a problem is if any flower name would have a space in the name. This could throw the whole program off when it comes to the space. In place of using
fin >> flowerName
use
std::getline(fin, flowerName);
in the while condition and a second "getline" inside the while loop to get the lighting.
So unless you are guaranteed that the flower name will always be one word it would be better to use "std::getline()" and be safe.
Hope that helps,
Andy