I am having a problem when trying to specify a directory to put my txt file containing the output data.
Now this works, but it puts the log.txt into my home directory instead of the program directory. When I change the ofstream to put it somewhere else, such as:
logfile.open ("~/Desktop/log.txt", ios:
ut);
it gives me an error. I've tried changing the permissions for the C++ file but that produces the error message as well. Any help would be appreciated.
Thanks.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream logfile;
logfile.open ("log.txt", ios::out);
if (!logfile){
cout << "Error" <<endl;
return 1;
}
for ( i=0; i<5; i++ ) {
cout << "the robot is at location (" << x << "," << y << ")" << endl;
cout << "which way should roomba move (enter F,B,L,R or Q)? ";
cin >> c;
logfile << "You entered " << c << endl;
if (( c=='F' ) || ( c == 'f' )){
y = y + 1;
}
else if (( c=='B') || ( c == 'b' )) {
y = y - 1;
}
else if (( c=='L') || ( c == 'l' )) {
x = x - 1;
}
else if (( c=='R') || ( c == 'r' )) {
x = x + 1;
}
else if (( c=='Q' ) || ( c == 'q' )) {
q = true;
}
else {
cout << "Oops! you entered something invalid. please try again" << endl;
}
}
logfile.close();
return(0);
}
Now this works, but it puts the log.txt into my home directory instead of the program directory. When I change the ofstream to put it somewhere else, such as:
logfile.open ("~/Desktop/log.txt", ios:
it gives me an error. I've tried changing the permissions for the C++ file but that produces the error message as well. Any help would be appreciated.
Thanks.