loops - Writing On Text File C++ -


i trying program write "test" created file. however, when run code below there no file in working directory. running code on mac , compiling using gcc terminal.

    // writing on text file #include <iostream> #include <fstream> using namespace std;  int main () {   ofstream myfile ("example-1.txt");   if (myfile.is_open())   {     myfile << "this line.\n";     myfile << "this line.\n";     if (myfile.fail())        cout << "fail" << endl;     myfile.close();   }   else cout << "unable open file";   return 0; } 

all code posted valid , works. however, compiling via command line on mac osx using gcc. command looks this:

g++ -g nameofinputfile.cpp -o nameofoutput.out 

this works fine, when open .out file (compilation file) example-1.txt file created @ root of users file documents, desktop, downloads etc. exist. have state created. refer question learn how specify directory in code.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -