Ofstream in C++ - where is the file


#1

Using the code below, I try to create a text file based on user input. Where is the file saved?

#include
#include <string.h>
#include
using namespace std;
typedef struct testStruct{
int rank;
string name;
} testStruct;
int main() {
string name;
char choice = ‘y’;
testStruct tester[100];
int i;
for (i=0;i<100;i++){
if (i>0){
cin >> choice;
}
if (choice == ‘n’){
i–;
break;
}
if (choice == ‘y’){
tester[i].rank = i+1;
cout<<endl<<"Enter the name of the " << i+1 << “th item.” << endl;
cin >> tester[i].name;
cin.sync();
cout << endl << “Do you want to enter another name? y/n?”;
}
}
fstream names;
names.open (“https://ide.c9.io/benjiperry/cpp_sandbox/names.txt”);
while ( getline (names,name) ){
cout << "Read: " << name << endl;
}
cout << “test: i=” << i;
for(int j=0;j<i+1;j++){
cout << endl << "Write: " << tester[j].name;
names << tester[j].rank << " " << tester[j].name << endl;
}
names.close();
}