ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I just tried your example code but changed it to:

ofstream myfile("example.txt", ios::out | ios::binary);
myfile << "Writing this to a file.\n";
myfile.close();

This created and wrote to "example.txt" in the directory that I ran the node from. I tried running from several different directories, and each time the file "example.txt" showed up in the directory I was in, and had nothing to do with the location of the node binary.

click to hide/show revision 2
Cleaning up thanks to @joq's comment.

I just tried your example code but changed it to:

#include <fstream>
using namespace std;
.
.
.
ofstream myfile("example.txt", ios::out | ios::binary);
myfile << "Writing this to a file.\n";
myfile.close();

This Edit: Cleaning up thanks to @joq's comment.

Using rosrun this created and wrote to "example.txt" in the directory that I ran the node from. I tried running from several different directories, and each time the file "example.txt" showed up in the directory I was in, and had nothing to do with the location of the node binary.

Using roslaunch this created and wrote "example.txt" in ~/.ros no matter which directory I run the roslaunch command from.