Consider the C++ program below and the contents of the file data1.txt. After the
ID: 3801649 • Letter: C
Question
Consider the C++ program below and the contents of the file data1.txt. After the program runs, show exactly and contents of data2.txt. #included #include using namespace std; int main() {string s1, s2; ifstream infile; ofstream outfile; infile.open("datal. txt"); outfile. open("data2. txt "); for (int I = 1; I > s1 >> s2; outfile.close(); infile.close(); outfile.close();} Assume the file datal.txt has the following lines followed by a fifth line which is blank: We have many a very good days vacation next month!! Give the EXACT contents of data2.txt:Explanation / Answer
#include<fstream>
#include<string>
using namespace std;
int main(int argc, char const *argv[])
{
string s1,s2;
ifstream infile;
ofstream outfile;
infile.open("data1.txt");
outfile.open("data2.txt");
for (int i = 1; i < 5; ++i)
{
infile>>s1>>s2;
outfile<<s2<<endl;
}
infile.close();
outfile.close();
return 0;
}
===============================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ g++ data.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
data1.txt
We have many
a very good
days vacation next
month ! !
data2.txt
have
a
good
vacation
=============================================================
Let me know if you have any doubt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.