Can't find File Output

This is the code. I'm using Xcode. Where can I find quotes.txt on my pc???


#include <iostream>
#include <string>
#include <fstream>

int main(int argc, const char * argv[])
{
std::string quote, speaker;

std::cout << "Enter a quotation:\n";
std::getline(std::cin, quote);

std::cout << "Enter the name of the author:\n";
std::getline(std::cin, speaker);

std::cout << "\n";

std::cout << "This is the quote you entered:\n\n" << quote << "\nby: " << speaker << "\n\n";

//Define a file object
std::ofstream fileOutput("quotes.txt", std::ios::app);

//If the file is open, record the data
if (fileOutput.is_open()) {
//Write the data to the file
fileOutput << quote << "|" << speaker << "\n";

//Close the stream
fileOutput.close();

//Print a message
std::cout << "The quote has been saved!";
} else {
//Couldn't open file
std::cout << "The file could not be opened!";
//Indicates a problem has occured
return 1;
}

std::cin.get();

return 0;
}
It will be in the same folder/directory as the executable program. Note, that need not be the same location as the source code.
Last edited on
It will be in the working directory, not necessary in the same directory as the executable.
I opened the package contents of Xcode and found this:

http://i723.photobucket.com/albums/ww234/padfoots666/ScreenShot2012-12-26at53147PM_zps7e241bae.png

I opened some of the folders but I can't find it =/ Is this what you meant by working directory?
Use something like getcwd() in your program to find the working directory and print it to the console.

http://www.mkssoftware.com/docs/man3/getcwd.3.asp
Topic archived. No new replies allowed.