Skip to content

Instantly share code, notes, and snippets.

@afifabroory
Last active July 30, 2021 15:48
Show Gist options
  • Save afifabroory/e03c2179550c72828ea40bd38d909e0e to your computer and use it in GitHub Desktop.
Save afifabroory/e03c2179550c72828ea40bd38d909e0e to your computer and use it in GitHub Desktop.
My solution for ods exercises 1.1 (1)
#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