Question
help with printing the last line of all paragraph in a given text file specified as command-line argument. Assignment STARTER CODE #include #include #include #include
help with printing the last line of all paragraph in a given text file specified as command-line argument.
Assignment
STARTER CODE
#include
void printAllLine(std::istream& is, std::ostream& os){ std::string line; while (std::getline(is, line)) { std::cout
void printLastLine(std::istream& is, std::ostream& os){ }
int main(int argc, char** argv) {
std::ifstream paras(argv[1]); std::ofstream parasOut(argv[2]); printAllLine(paras, std::cout);
//printLastLine(paras, std::cout); //printLastLine(paras, parasOut); return 0; }
PART 2 File I/O using file streams When working on programs, you should be periodically saving and compiling your source code to ensure it compiles successfully! In general, when coding you should save and compile your C++ program after every 4 to 5 lines of change. Exercise/Program requirement: Develop a C++ program that prints the last line of each paragraph in a given text file specified as command-line argument. Paragraphs are separated by one or more blank (i.e., empty) lines. Procedure: Work on this exercise in the following manner: 1. Use the NetBeans project created in the earlier step (supplied starter code PrintAllLines.cpp) 2. Clean-up the starter code and ensure it compiles and runs successfully 3. In order gain practice working with generic I/O streams, add the following method that works with abstract streams to your starter code: void printLastLine(std::istream& is, std::stream& os) The above method is the one that should process lines from input stream is (use std::getline to read lines) and print last line of each paragraph to output stream os. 4. Call the printLastLine method (from main) with a suitable std::ifstream to process data from a given text file specified as a command-line argument. Recollect that the file name will be in argy[1] in the main method. Use std::cout as the output streamStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started