Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This lab provides practice for file streams. Suppose that you know that the file

ID: 3670662 • Letter: T

Question

This lab provides practice for file streams. Suppose that you know that the file inData.txt contains two integers on the first line, a character on the second line, and a string message (without spaces) the third line. Type in the shell of the program below Add the statement that includes the fstream header file in the program Declare variables of type ifstream and ofstream. Open an input file, called inData.txt and an output file called outData.txt. Read the data from the input file. After reading the two integers, print the sum of the two numbers to the output file. After reading the character, print the character that follows it in the ASCII sequence to the output file. After reading the string, print it to the output file. Close the files. Run your code on different input files, including the one below: 23 57 R Howdy!

Explanation / Answer

#include <iostream>
#include <fstream>
#include<string>

using namespace std;
int main (){

ifstream inFile;
ofstream outFile;
inFile.open("inData.txt");
outFile.open("outData.txt");

   string str;
int first,second;
char c;
inFile>>first;
inFile>>second;
outFile<<(first+second)<<endl;
inFile>>c;
outFile<<c<<endl;
inFile>>str;
outFile<<str<<endl;
inFile.close();
outFile.close();
//cout<<first<<" "<<second<<" "<<c<<" "<<str<<endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote