Last active
July 30, 2021 15:48
-
-
Save afifabroory/e03c2179550c72828ea40bd38d909e0e to your computer and use it in GitHub Desktop.
My solution for ods exercises 1.1 (1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <stack> | |
using namespace std; | |
void read_input(string fileName, stack<string>& stackText); | |
void write_input(stack<string> stackText); | |
int main(void) | |
{ | |
const string fileName = "HelloWorld.txt"; | |
stack<string> textLine; | |
read_input(fileName, textLine); | |
write_input(textLine); | |
} | |
void read_input(string fileName, stack<string>& stackText) | |
{ | |
ifstream myFile(fileName); | |
string textLine; | |
while (getline(myFile, textLine)) { stackText.push(textLine); } | |
} | |
void write_input(stack<string> stackText) | |
{ | |
while (!stackText.empty()) | |
{ | |
cout << stackText.top() << endl; | |
stackText.pop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment