#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void writeFile(fstream& file)
{
file.open("writing.txt", ios::out);
if (file.is_open())
{
string holdLine;
cout << "Please write to the file from console!!!" << endl;
while (getline(cin, holdLine, '-'))
file << holdLine<< endl;
}
file.close();
}
void readFile(fstream& file)
{
file.open("writing.txt", ios::in);
if (file.is_open())
{
string holdLine;
while (getline(file, holdLine))
{
cout << holdLine << endl;
}
}
file.close();
}
int main()
{
fstream sampleFile;
writeFile(sampleFile);
readFile(sampleFile);
}
// I am guessing this while (getline(cin, holdLine, '-')) loop is the one causing problem // I test readFile() and it works fine but whenever writeFile() runs it goes on infinite loop