Hi there, im currently learning about the <fstream> library
Basically im to write two programs, one to write to a file(app1), and one to read from the file that was created from the first app(app1)
heres some code ive written to help explain my question:
The below code is for the app ive built to create a .txt file called "Student Names" and writes "John" "James" & "Joe" to that file
Code:
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ofstream sfile ("Student Names");
cout << "\nThis program will store some names to a file called 'Student Names'";
sfile << "John" << "\nJames" << "\nJoe";
sfile.close();
return 0;
}
the path for the above app is stored in /home/user/workspace/StudentW
The second program ive written, im trying to read from the "Student Names" file created in the first app, and to print in the consol shell:
Code:
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
char str[50];
ifstream sfile ("Student Names");
cout << "\nThis program will read the names from 'Student Names' created from the 'StudentW' app";
sfile >> str;
cin.get();
return 0;
}
Because the second app is store in /home/user/workspace/StudentR how do i apply the path in the ifstream class?
Thanks in advance