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

Where are the text files

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

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;
            myfile1.open("/home/Desktop/time.txt", std::ios_base::app | std::ios_base::out);
            myfile1 << "abc \n";
            myfile1.close();
            std::ofstream myfile2;
            myfile2.open("/home/Desktop/position.txt", std::ios_base::app | std::ios_base::out);
            myfile2 << "%f %f %f \n"<<x,y,z;
            myfile2.close();

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
1

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

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

Comments

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

jason gravatar image jason  ( 2017-10-16 12:56:30 -0500 )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 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 536 times

Last updated: Oct 10 '17