question

Erri-2940 avatar image
0 Votes"
Erri-2940 asked MinxinYu-MSFT edited

adding directories and data to empty c++ project

Hi I have a c++ project and I want to add directories and files to the directory the .exe file will be in when debugging basically I want to add the directory data and the file time.db to the directory data in the directory the exe file will be in so when it's run it will have the resources available? how does this work with visual basics? If I use fopen("data/time.db", "w") should i put the files in a certain directory? because data directory wont be there and I think it will give me an error. Like should I add a filter and if so where should it be added in the sources filter or in its own filter and how should I access it with fopen. Thanks for your patience. Also I used c++ filter cause that's the only one for c programming and this program is in c.

Lastly if there is a different way then using the fopen statement that visual basic programmers use I'm ears. I am very new to visual basics and also I am not a student I am just a hobbyist.

c++
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

how does this work with visual basics?

Are you using C++ or Visual Basic?

fopen("data/time.db", "w")

If you use the flag w, the original time.db will be deleted. For your reference: fopen


0 Votes 0 ·

I know that but it won't even work without a data directory and I'm asking where to add the data directory in the visual studios solution. and also how to add the directory or if its just a filter it looks for and should the filter be in source files or in the solution.

0 Votes 0 ·

fopen is not safe now. Try to use fopen_s.

I want to add directories and files to the directory the .exe file will be

The snippet works for me. Your path parameters should be handled with care.

 FILE* stream;
 errno_t err; 
 err = fopen_s(&stream,"../x64/Debug/file.txt", "w");




0 Votes 0 ·
Show more comments

1 Answer

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered

By default when debugging a C++ project the visual studio debugger will set the working directory for the program being debugged to the folder that contains your project file (.vcxproj).

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.