Using PUTTY
We will create functions.h and functions.cpp to separate the read and write function from main function. Use the following steps:o Create a directory called lab07o Upload the yourlastnameFirstnameLab06a.cpp from your computer to the csegrid.
Create a functions.h file with the following:
#ifndef _READWRITE
#define _READWRITE
void readWrite( );
#endif
Create a functions.cpp#include functions.hImplement readWrite() with the code in case 1 of the main.cpp.
Modify yourlastnameFirstnameLab06a.cpp
#include functions.h
Call readWrite for case 1 (instead of the case1 code)
Compile your code with the command:g++ -lab06a main.cpp functions.cpp
#ifndef _READWRITE #define _READWRITE void readWrite( );
#endif
Create a functions.cpp #include functions.h Implement readWrite() Modify main.cpp #include functions.h Call readWrite
Compile your code with the command: g++ -o lab06a yourlastnameFirstnameLab06a.cppfunctions.cpp
Please let me know if you need any other information.
Thank you
Here is the solution to your question. I tried my
best to solve your doubt, however, if you find it is not as good as
expected by you. Please do write your further doubts regarding this
question in the comment section, I will try to resolve your doubts
regarding the submitted solution as soon as possible.
Please give proper indentation as shown in the screenshot
If you think, the solution provided by me is helpful to you please
do an upvote.
As you have not provided anything for the function readWrite(), I am solving your problem by defining a dummy function that simply reads and writes files.
#include <iostream> #include "functions.h" int main() { readWrite(); return 0; } |
#ifndef _READWRITE #define _READWRITE void readWrite( ); #endif |
#include <iostream> #include <fstream> #include "functions.h" using namespace std; void readWrite() { // Writing // Create and open a text file ofstream MyFile("filename.txt"); // Write to the file MyFile << "data to be written\n"; // Close the file MyFile.close(); // Reading // Create a text string, which is used to output the text file string myText; // Read from the text file ifstream MyReadFile("filename.txt"); // Use a while loop together with the getline() function to read the file line by line while (getline (MyReadFile, myText)) { // Output the text from the file cout << myText<<endl; } // Close the file MyReadFile.close(); }
|
Get Answers For Free
Most questions answered within 1 hours.