Last active
July 31, 2021 04:49
-
-
Save afifabroory/e4be703c1240a2df186601420ca86dfe to your computer and use it in GitHub Desktop.
My solution for ods exercises 1.1 (2)
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_fifty_input(ifstream* myFile); | |
void write_input(stack<string>& stackText); | |
int main(void) | |
{ | |
const string fileName = "HelloWorld.txt"; | |
ifstream myFile(fileName); | |
read_fifty_input(&myFile); | |
} | |
void read_fifty_input(ifstream* myFile) | |
{ | |
string textLine; | |
stack<string> stackLine; | |
int counter = 0; | |
while (getline(* myFile, textLine)) | |
{ | |
if (counter >= 50) { | |
write_input(stackLine); | |
cout << endl; | |
stackLine.push(textLine); | |
counter = 1; | |
} | |
else | |
{ | |
stackLine.push(textLine); | |
++counter; | |
} | |
} | |
if (!stackLine.empty()) | |
{ | |
write_input(stackLine); | |
} | |
} | |
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