Question

In: Computer Science

Write a C++ pgm which 1.reads an input file named 'input.txt' 2.content of input.txt are not...

Write a C++ pgm which

1.reads an input file named 'input.txt'

2.content of input.txt are not known to you

3.copies content of input file into an output file named 'output.txt'

4.contents of output.txt should be exactly the same as contents of input.txt

5.the user should be given a choice to select input and output file in any folder

6.remember to check that input file opened successfully

Solutions

Expert Solution

SOURCE CODE:

#include <iostream>
#include<string>
#include <fstream> //including c++ standard libray fstream for file operations
using namespace std;
int main()
{
string s;
string Str="";
string InFileName="";
string OutFileName="";
cout<<"Enter input file name: ";
getline(cin,InFileName); //reading input file name from user
ifstream myfile(InFileName.c_str()); //ifstream is used to read information from file
if(myfile.is_open()) //checking whether the file is opened or not
{
while(getline(myfile,s)) //while loop for reading file line by line to a string 's'
{
Str=Str+s+"\n"; //adding s to Str for further processing
}
myfile.close(); //closing ifstream
}
else //if file is not opened then printing message
{
cout<<"File opening not successful"<<endl;
   return 0;
}
cout<<"Enter ouput file name: ";
getline(cin,OutFileName); //reading output file name from user
ofstream file(OutFileName.c_str()); //ofstream is used to write information to file
file<<Str<<endl; //writing information to file that is stored in the string 'Str'
file.close(); //closing ofstream
cout<<"Information from "<<InFileName<<" to "<<OutFileName<<" copied successfully"<<endl;
return 0;
}

CONSOLE OUTPUT:

input.txt

Output.txt


Related Solutions

Write a program in c that reads the content from the file and stores each line...
Write a program in c that reads the content from the file and stores each line in an int array in heap(using dynamic memory allocation). For example, let the file has elements following (we do not know the size of files, it could be above 100,000 and contents of the file and make sure to convert file elements to int): 10067 26789 6789 3467
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt and determines the following: The number of uppercase letters in the file The number of lowercase letters in the file The number of digits in the file Prompts And Output Labels. There are no prompts-- nothing is read from standard in, just from the file text.txt. Each of the numbers calculated is displayed on a separate line on standard output, preceded by the following...
Write a program which reads an input file. It should assume that all values in the...
Write a program which reads an input file. It should assume that all values in the input file are integers written in decimal. Your program should read all integers from the file and print their sum, maximum value, minimum value, and average. Use the FileClient class here (from a previous reading) as an example. You'll need to create a file to be used as input to test your program, as well. Your program should work whether the integers are separated...
Write a C program that, given a file named Program_2.dat as input, determines and prints the...
Write a C program that, given a file named Program_2.dat as input, determines and prints the following information: The number of characters in the file. The number of uppercase letters in the file. The number of lowercase letters in the file. The number of words in the file. The number of lines in the file. Your program should assume that the input file, Program_2.dat, may contain any text whatsoever, and that text might be, or might not be, the excerpt...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using Notepad) into a one-dimensional array and then analyzes the numbers as described below. Your program must use loops to read the numbers into the array and to analyze the contents of the array. The program’s main function should do the following:  Read eight floating-point numbers from the file named numbers.txt into a onedimensional array, displaying each number on the screen.  Pass the...
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. The whole program is under 40 lines of code. Just read from cin. Now, you need to detect non integers. In this case,...
2. Write a Java program that reads a series of input lines from given file “name.txt”,...
2. Write a Java program that reads a series of input lines from given file “name.txt”, and sorts them into alphabetical order, ignoring the case of words. The program should use the merge sort algorithm so that it efficiently sorts a large file. Contents of names.text Slater, KendallLavery, RyanChandler, Arabella "Babe"Chandler, StuartKane, EricaChandler, Adam JrSlater, ZachMontgomery, JacksonChandler, KrystalMartin, JamesMontgomery, BiancaCortlandt, PalmerDevane, AidanMadden, JoshHayward, DavidLavery,k JonathanSmythe, GreenleeCortlandt, OpalMcDermott, AnnieHenry, DiGrey, MariaEnglish, BrookeKeefer, JuliaMartin, JosephMontgomery, LilyDillon, AmandaColby, LizaStone, Mary FrancesChandler, ColbyFrye, DerekMontgomery,...
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT