Fork, Commit, Merge - Medium Issue (C++)
nikohoffren opened this issue · comments
Fork, Commit, Merge - Medium Issue (C++)
Implement a Simple File Reader/Writer Class and Methods in C++
Note: You don't have ask permission to start solving the issue or get assigned, since these issues are supposed to be always open for new contributors. The actions-user bot will reset the file back to previous state for the next contributor after your commit is merged. So you can just simply start working with the issue right away!
Navigate to the tasks/c++/medium
directory from the root of your project.
You will see four files: main.cpp
, FileHandler.cpp
, FileHandler.h
and text-file.txt
.
You only need to modify FileHandler.cpp
and FileHandler.h
files for this task.
Description:
Create a simple class and methods in C++ to handle reading and writing text files. The class should have the following functionalities:
- Read File: Read the content of a given text file and return it as a string.
- Write File: Write a given string to a specified text file.
- Append File: Append a given string to the end of a specified text file.
- File Exists: Check if a file exists at a given path.
Requirements:
- Implement the FileHandler class in
FileHandler.h
file - Implement the FileHandler::ReadFile method, FileHandler::WriteFile method, FileHandler::AppendFile method and FileHandler::FileExists method in
FileHandler.cpp
- Do not modify the
main.cpp
ortext-file.txt
files - Proper error handling should be done to handle cases where the file does not exist, or other file-related issues occur.
Compiling and Running
To test the program you have to first make sure you are in the right directory:
cd tasks/c++/medium
Then compile the files:
g++ FileHandler.cpp main.cpp -o filehandler
Then you can run the compiled program by running:
./filehandler
Expected Output:
There is a file called text-file.txt
where you should now see this:
Hello, World!
Appended text.
And this should be printed to the console:
Write successful.
Append successful.
File content:
Hello, World!
Appended text.
File exists.
If the program works as requested in the task, you are ready to make a pull request!
To work with this issue, you need to have C++ installed to your local machine.
Check out README.md for more instructions of installing C++ and how to make a pull request.
Feel free to ask any questions here if you have some problems!