What is wrong with my flowers

So I have a flowers.dat file and my program is to read the .dat file and then I must write a while loop to read the input until EOF is reached, in the body of the loop print the name of each flower and where it can be grown. When I execute the program it does not output anything from my file. It compiles and I used the example in my book to develop the code thus far. Any pointers of where I went wrong would be helpful. I am using C++

// Flowers.cpp - This program reads names of flowers and whether they are grown in shade or sun from an input
// file and prints the information to the user's screen.
// Input: flowers.dat.
// Output: Names of flowers and the words sun or shade.

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Declare variables here
string flowerName, flowerTemp;
ifstream data_in;
ofstream data_out;

// Open input file
data_in.open("flowers.dat");
data_in >> flowerName;
data_in >> flowerTemp;

// Write while loop that reads records from file.


while (!data_in.eof())
{
data_in >> flowerName;
data_in >> flowerTemp;
// Print flower name
data_out << flowerName << endl;
data_out << flowerTemp << endl;
}
data_out.close();
return 0;
} // End of main function
closed account (E0p9LyTq)
ofstream data_out; opens a file, but there is no file name. You are throwing away all your output.

Why are you writing the data back out to a file? You are basically copying a file, without creating a copy. Maybe you should output the file to the console screen?

PLEASE use code tags, it makes it easier to read your code (you can edit your post to add them):

How to use code tags
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.