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

Where are the text files

asked 2017-10-09 16:49:52 -0600

jason gravatar image

Hello, I am using ROS to control the Crazyflie and I need to log the distance, velocity data to do analysis. I use this code:

            std::ofstream myfile1;
  "/home/Desktop/time.txt", std::ios_base::app | std::ios_base::out);
            myfile1 << "abc \n";
            std::ofstream myfile2;
  "/home/Desktop/position.txt", std::ios_base::app | std::ios_base::out);
            myfile2 << "%f %f %f \n"<<x,y,z;

It is only part of my code. However, after I use "Ctrl+C" to stop the code, I cannot find the two text files on my desktop. I am pretty sure that the code has gone through this part, then I use "Ctrl+C"

Does anyone know why is it? Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-10 02:35:33 -0600

Alberth gravatar image

Assuming you pressed CTL+C after you executed the above code, what exactly is your home directory? Usually a path in your home directory is "/home/YOURUSERNAME/..." rather than "/home/...". Type "echo $HOME" at the shell (without the quotes) to find out what the system thinks you home is.

As for the files, did you try "ls /home/Desktop/time.txt" (ie literally copy/paste the path from your code)? If it exists, the file is listed, else you get an error the file cannot be found. However, likely the latter happens, unless you have a user named "Desktop" :p

edit flag offensive delete link more


thanks. with "echo $HOME" I can figure the correct directory.

jason gravatar image jason  ( 2017-10-16 12:56:30 -0600 )edit

You can also query environment variables from within C/C++ by using getenv, like 'const char *home = getenv("HOME");' Be sure to check for NULL return value if the variable doesn't exist. For details, read getenv(3) (That is, the man-page about getenv in section 3.)

Alberth gravatar image Alberth  ( 2017-10-18 02:02:56 -0600 )edit

Question Tools

1 follower


Asked: 2017-10-09 16:49:52 -0600

Seen: 286 times

Last updated: Oct 10 '17