Help with file output.

I'm trying to make it so my finished madlibs is outputted into a new file. I can't seem to get it to work. I really need help. I'm pulling hair here.
https://gist.github.com/anonymous/c4420f4d64621328d3d6
[/code]
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
//prototyping functions so they can be called anywhere.
void instructions();
string askForFileName(string prompt);
string madLibString(string fileName);
string doneMadLib(string madLibFINISHED);
static string getaString(string prompt);
void outPutnewMadlib(string fileName, string madLib);
//MAIN
int main()
{
string madLibFileName, fullMadLib, completeMadLib,fileName,madLib; // defining string variables to be used
instructions(); //assks for instructions
string askFileName("File name");
madLibFileName = askForFileName(askFileName); // calls a function
fullMadLib = madLibString(madLibFileName); // calls a function
completeMadLib = doneMadLib(fullMadLib); // calls a function
cout << endl << completeMadLib << endl; // output
outPutnewMadlib(fileName, madLib);
return 0;
}
void instructions()
{
string answer;
string askInstructions("Ask for instructions (yes or no)"); //fancy bullsh*t
answer = getaString(askInstructions); // I'm going to get rid of this.
string instructions("Instructions here");
// delete this part
if(answer == "yes")
{
cout << endl << instructions << endl;
}
else if(answer == "no")
{
cout << endl;
}
}
// returns a name
string askForFileName(string prompt)
{
string answer;
string name = getaString(prompt);
if(name == "quit")
{
answer = " ";
}
else
{
answer = name;
}
return answer;
}
string madLibString(string fileName)
{
string madLibParts, tempString;
ifstream fin(fileName.c_str());
if(fin.is_open())
{
cout << "File was Opened" << endl;
}
else
{
cout << "File not found" << endl;
system("PAUSE"); //again pointless fancy shit you don't need.
return 0;
}
fin >> madLibParts;
while(! fin.eof())
{
fin >> tempString;
madLibParts = madLibParts + " " +tempString;
}
fin.close();
return madLibParts;
}
//function takes a string, then changes it around. So we have to define it based on the way it is in the program specs Dr.Kaplan gave us.
string doneMadLib(string madLibFINISHED)
{
string madLibASK;
string identify("**");// identifies what to change based upon the asteriks. I tried numerous combinations. This seemed best.
int identifyStart = madLibFINISHED.find(identify);
int identifyEnd = madLibFINISHED.find(identify, identifyStart+1);
string fillIn, beforeidentify, afteridentify;
bool fillingIn = true;
cout << endl;
cin.ignore();
while(identifyStart != -1)
{
madLibASK = madLibFINISHED.substr(identifyStart+identify.length(), (identifyEnd-identifyStart-identify.length()));
cout << endl << "Please enter a " << madLibASK << ": ";
getline(cin, fillIn);
beforeidentify = madLibFINISHED.substr(0, identifyStart);
afteridentify = madLibFINISHED.substr(identifyEnd+identify.length(), (madLibFINISHED.length()-identifyEnd+identify.length()));
madLibFINISHED = beforeidentify + " " + fillIn + " " + afteridentify;
identifyStart = madLibFINISHED.find(identify);
identifyEnd = madLibFINISHED.find(identify, identifyStart+1);
}
return madLibFINISHED;
}
static string getaString(string prompt)
{
string answer;
cout << prompt << endl;
cin >> answer;
return answer;
}
void outPutnewMadlib(string fileName, string madLib) //This part isn't working. Atleast I don't think it is.
{
string newFileName = fileName + "_output.txt";
ofstream fout ("");
fout << madLib;
fout.close();
}
[/code]
Last edited on
Topic archived. No new replies allowed.