Can you refer to a file outside the folder of your program in C++? - file

I have been doing C++ for quite long. and when I refer to files say .txt, .jpg, .png anything... in my source code, I have to put those files in the same folder where my source code is located. That is, if say for example: I wanted to view a picture with a name "somepic.png" on the GUI using SDL through the code I wrote in my "sdlimage.cpp" file found in the path C:\documents\sdlimage.cpp, I have to move the "somepic.png" file to this same "C:\documents" folder otherwise it won't work.
this made my folder so messy and everytime I open Atom editor, it contains those files like images and fonts which you can do no coding with and makes the real codes I wanna work with, hardly navigable.
as you can see there are barely visible .cpp or .h files in the tab
So please help me.
can I use "..\folder\file.txt" in c++ just like how we use it on html and CSS too?

Related

Associating multiple extensions with a single file

I want to associate multiple extensions with the same file so that if you change the file extension different content is revealed. For example, a file named file1.jpg contains an image and when you change the extension to file1.txt it opens as a text file.
I know it may seem strange (why not have two separate files?) but it’s for an easter egg in a project I’m doing. Does anyone have an idea how this could be done?

How to remove these generated files from my file explorer?

I have a problem in my VSCode explorer.
After I build (filename).c files, some documentary files appear in my files explorer.
What is this documentary file?
How to avoid showing this documentary file?
Thanks for all your comment :)
I think most probably that 'documentary' file will become a .exe file once you run your code. Don't worry about it. Write your code and run the code.I have something similar with my C++ files.Don't know about the hiding part though.My file explorer also looks similar

How to include header AND source files folder in Visual Studio

I am using Visual Studio (2017) and I need the following.
I have a folder where a code generator puts the .h and .c files obtained from a formal model. This folder is not controlled by me, e.g. I cannot write in it, but it is updated by another team member.
By using the /I compiler options (or Additional include directories in the project properties) I managed to import all the generated header files in my VS project. What I am supposed to do is to integrate this generated code into a specific platform, this means that I have to compile both the generated code and the integration code on the target platform. The problem is, the compiler is not able to resolve the generated function definitions of the generated code as it only sees the .h files. What I got is a linking error (external symbol not resolved)
To solve the problem, I added the existing .c files manually, one by one. The obvious problems that comes with this solution are
manual boring work
when new files are generated, I need to manually import the new files
Question is: is there an option that can be set in order to specify the path of the source files without passing them one by one?
note: just copying and pasting the generated code in the VS project folder is not an acceptable solution.
Thanks
If you look at https://learn.microsoft.com/en-us/cpp/ide/working-with-project-properties?view=vs-2017 then you see there is a Source Directories property that has $(VC_SourcePath) as a default but (I think) to which you can add additional paths. The documentation is unclear whether that means all source files in such a path will be included for compilation.
At the bottom of the documentation it explains how to override certain project properties by providing an external properties file. It seems you can override the targets/sources using such a file. You can generate the file using a small tool that reads the filenames in those directories and adds them to the file.
You could also analyze the .vcproj file and build a small tool that wil re-write the part with your generated source directories, reading the filenames in those directories and adding them to the section in the .vcproj file.

How do I can view what is really inside an *.asi file?

I have a file with .asi extension working as a plug-in of another program, and I wanna to see what's inside that file so I can understand how this plug-in works.
I tried to open my file with some programs such as File Viewer Plus and Notepad++ but I only see a series of strange characters. How do I can see what's inside my file?

How to import files from computer?

I have been making a simple program on my computer using Dr. Java, and I would like to know how to move it to my android on AIDE. I can easily get the files onto the android, I just can't figure out how to make AIDE compile and run them.
Thanks!
Using My Files or the file browser you prefer, move your entire project directory into a folder call AppProjects. Should be fairly easy to open from there. Also you will want to make sure the directory is set up correctly. If all else fails, you can always recreate the project using AIDE and copy your java files into the java folder and XML files into the layout folder, and your images and icons into the drawable folders. These folders are automatically generated by AIDE so you don't have to create them.
You can copy the source files normally as you do with other files but Desktop's Java is not always same as Android's. So it needs some more coding and editing to make the code work as you want. But if the code is so simple, it can work.

Resources