Need help with input from a file

Write your question here.

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
  
// 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
   ifstream fin;
   string flowerName;
   string flowerGrow;
   		
   		
   		
   // Open input file
   fin.open("flowers.dat");
   fin >> flowerName;
   fin >> flowerGrow;
   while (!fin.eof())
   
   
   // Write while loop that reads records from file.
  {
  
   
   fin >> flowerName;
   fin >> flowerGrow;
   
      // Print flower    
    cout << flowerName <<endl;
    cout << flowerGrow <<endl;
  } 
   
   fin.close(); 	
   return 0;
} // End of main function


okay it is printing out all of the items except the first 5 things

Astilbe
Shade
Marigold
Sun
Begonia doesnt print anything above the line
~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
sun starts printing out here
Primrose
Shade
Cosmos
Sun
Dahlia
Sun
Geranium
Sun
Foxglove
Shade
Trillium
Shade
Pansy
Sun
Petunia
Sun
Daisy
Sun
Aster
Sun



Last edited on
Topic archived. No new replies allowed.