Lab 3

Store all of your files for this lab in a folder named "lab3".

When working with streams, there are three main ways to read data from them:

Statements like any of the three shown above can be used as the condition of a loop or if statement, the condition will be false if the reading operation failed.

Exercise 1

Create a program that copies a file. The program should ask the user for two file names first: the file to copy from and the file to copy to. Name your source file and program: cp.cpp and cp, respectively.

Exercise 2

Create a program that compares two files and displays the character position of where they differ (if any). The program should ask the user for two file names first. Name your source file and program: cmp.cpp and cmp, respectively.

Exercise 3

Create a program that sorts the lines within a file alphabetically. The program should ask the user for the name of the file to sort. Name your source file and program: sort.cpp and sort, respectively.

Hint: You can use the sort function from <algorithm>

Exercise 4

Create a program displays the count of lines, words, and non-whitespace characters in a file. Name your source file and program: wc.cpp and wc, respectively.

Hint: You can use istringstream.