Bora Atalay Bora Atalay - 1 year ago 80
C++ Question

How to customize save folder

When I save a data via .save function, the file is saved under the folder where I have my cpp project.

I would like to save my data to a folder which I've specified. How can I do that?


mat histreal; //data I want to save."histname.dat", raw_ascii); //saved where my project is

A simple question, but I couldn't solve it. Thanks.

Answer Source

This is quite simple... just use the full path where you want to save your file. This is called "absolute path", compare to what you're doing, which is called "relative path". So, if you're using Windows:"C:/MyFolder/histname.dat", raw_ascii); 

If you're using Linux:"/home/myusername/MyDir/histname.dat", raw_ascii); 

Remember that in Windows you shouldn't use normal backslashes, i.e., C:\MyFolder\histname.dat, but instead either use slashes like I did / or use double backslashes \\. This is because a backslash combined with some other character normally can be replaced by other characters in a string. For example: \n is a new line, and \t is a tab.