Question

#include #include #include using namespace std; int main() { ifstream fin; fin.open ("flowers.dat", ios::in); //Declare variables...

#include #include #include using namespace std; int main() { ifstream fin; fin.open ("flowers.dat", ios::in); //Declare variables here string flowerName; string sun_shade; // Open input file if (fin.is_open()) { // Write while loop that reads records from file. while ( fin>>flowerName>>sun_shade) { // Print flower name cout << flowerName << " grows in the " << sun_shade << endl; } } fin.close(); return 0; } // End of main function

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<fstream>

using namespace std;

int main()

{

    ifstream fin;

   

    fin.open ("flowers.dat", ios::in);

   

    //Declare variables here

    string flowerName;

    string sun_shade;

   

    // Open input file

    if (fin.is_open())

    {

        // Write while loop that reads records from file.

        while ( fin>>flowerName>>sun_shade)

        {

            // Print flower name

            cout << flowerName << " grows in the " << sun_shade << endl;

        }

    }

   

    fin.close();

   

    return 0;

} // End of main function


------------------flowers.dat------------------

rose light
sunflower high

Sample Output

Add a comment
Know the answer?
Add Answer to:
#include #include #include using namespace std; int main() { ifstream fin; fin.open ("flowers.dat", ios::in); //Declare variables...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT