Visual Studio community 2019 cannot add cpp files to project - c++

file browser
Installation details
Main problem:
I have created a new, empty project and I want to populate it with
pre-existing .cpp files and a header file, but the file browser does
not allow the .cpp or .h extensions to show.
Possible cause 1:
I think it might be the installation details
Possible cause 2:
I have some legacy files from visual studio code
Context:
I migrated from using VS code to VS because code somehow wasn't able
to compile the 2 .cpp and 1 .h files my teacher gave me. I got tired
with messing about JSON files and compilers and such and threw in the
towel when my professor recommended the school's preferred IDE.

In Solution Explorer, right-click on your project and select Add → Existing Item... (You have probably clicked on the solution itself rather than on the project.)

Related

Comments and includes being collapsed when opening a .h or .cpp file in Visual Studio 2019

I have a Visual Studio 2019 solution that has many C++ projects. In one of the project, whenever I open up a .h or .cpp file, all of the comments and the includes at the top of the file are initially open but collapse after a couple of seconds. There is only one project that I have seen in this solution that does that.
I normally keep all the methods in the .cpp files collapsed and the editor does remember which methods were open when I close and re-open the file. I have searched the project .vcxproj, .filters, and .user files but can't find the setting that would cause this behavior. I recently deleted the solution .vs directory to fix a different problem so the setting do not appear to be kept there.
Has anyone else seen this behavior and know where the setting is to turn it off?

How do I run .cpp files in Visual Studio?

I have been following tutorials which have me download and unzip projects which contain .sln files for me to open. Following them this way is pretty easy. However, I want to be able to download a single .cpp file and run it without creating a project. I just want to get straight to into it. In Code::Blocks, setting this up is easy to figure out. For some reason, I can figure it out in Visual Studio.
I want to be able to download a single .cpp file and run it without creating a project.
You cannot. Visual Studio does not support this. A project is always required, even if it only contains a single source code (.cpp) file.
You can, however, run a single .cpp source file through Microsoft's C++ compiler on the command line (cl.exe), and then execute it. But this doesn't involve anything about the Visual Studio IDE.
if you have the source code, you could make a .cpp file by right-clicking and adding one and then ctrl+s then f5 and it might run... Idk.

Visual Studio 2019 is having several problems, including loading files

I have been working on a project for a while now (C++), in Visual Studio 2019, but I've suddenly run into several problems that send me in circles between them.
I loaded it one morning, and found that it couldn't load any of the files.
So thinking I must have accidentally moved files or something, I just copied my files again from my Github repository, but then it started having problems with every include file for the headers.
Manager.h is in a different folder in the project, which makes this more confusing to me because if the source files can't open a header file in the same solution, the headers should have problems opening a different header in a different part of the project.
I've tried deleting the project settings and reloading it, but VS won't reload them, and Github desktop is freaking out with any action with the project.
Cloning my repository again and loading that just sends me back to the first problem...
Anyone have any other ideas for what I can do?
Check to see if the files are in the folder present in the error message. If they are that can be a problem with the config files of the project/solution.
Possible solutions:
Since you have the project in the repository, a quick way to solve it would be to delete your local project and clone the repository project. (Or clone it to a different location)
You can try to repace the <Subscriber.h> by "Subscriber.h".
Create a new empty project and add all the project files through the Solution explorer:
right-click on the folder where you want to add the project (I recommend Source for the .cpp and Headers for the .h);
Select Add -> Existing item -> select the files.

I dont know how to connect SQLite with c++ on visual studio

im begginer as a sql programmer. I want to make my first app with data base. SQLite seems to be the best for me but i have no idea how it works. I have done what is written here: https://www.tutorialspoint.com/sqlite/sqlite_installation.htm but dont know what next. i downloaded the first one from here where are 2 files .h and 2 files .c .I suppose that i have to use it somehow, because i need to include SQLite in visual studio but dont know how
Just include the sqlite files into your project (that is in solution explorer right click on the project node and select Add->Existing files and then select the files, they should be copied into the project directory), you can then #include the header file and use sqlite calls from your own source.

Visual Studio can't 'see' my included header files

I created an empty 'Demo' project in Visual Studio 2008 and added some existing projects to my solution. Included "MyHeader.h" (other project's header) in main.cpp file which is in 'Demo'. Also added header files' path in "Tools/Option/VC++ Directories/Include files" section. But intellisense says: "File MyHeader.h not found in current source file's directory or in build system paths..."
How the problem can be fixed?
Delete the .sdf file that is in your solution directory. It's just the Intellisense database, and Visual Studio will recreate it the next time you open that solution. This db can get corrupted and cause the IDE to not be able to find things, and since the compiler generates this information for itself on the fly, it wouldn't be affected.
If you choose Project and then All Files in the menu, all files should be displayed in the Solution Explorer that are physically in your project map, but not (yet) included in your project. If you right click on the file you want to add in the Solution Explorer, you can include it.
This happened to me just now, after shutting down and restarting the computer. Eventually I realised that the architecture had somehow been changed to ARM from x64.
In Visual Studio 2019 in my case I copied a header file into the project directory, just near the other files. Intellisense could see it, but the build failed. Fair enough, it wasn't actually added to the project. I added it as existing item but this is the point that Visual Studio still didn't account for it.
Solution:
Close the project.
Delete the .vs directory.
Reopen the project.
Now Visual Studio recreates the directory with everything in it and it can now see the included file.
If it is the case that only the IDE indicates that it cannot find included files, but compiling is successful, the issue is simply that IntelliSense is not fully up to date with recent changes. This can happen specifically when including existing projects, in my own experience.
Deleting the .sdf file (= IntelliSense database) that is generated in your solution directory forces Visual Studio to regenerate it, so that it is up to date again. Just doing a "clean" will probably do the same thing, but takes more time since everything will be generated again then.
I know this is an older question, but none of the above answers worked for me. In my case, the issue turned out to be that I had absolute include paths but without drive letters. Compilation was fine, but Visual Studio couldn't find an include file when I right-clicked and tried to open it. Adding the drive letters to my include paths corrected the problem.
I would never recommend hard-coding drive letters in any aspect of your project files; either use relative paths, macros, environment variables, or some mix of the tree for any permanent situation. However, in this case, I'm working in some temporary projects where absolute paths were necessary in the short term. Not being able to right-click to open the files was extremely frustrating, and hopefully this will help others.
Had the same problem. Double check if you added the include files to Debug or Release Version of your project. If you only added it for one of them and compile for the other VS will just play dumb and not find them.
Try adding the header file to your project's files. (right click on project -> add existing file).
In my experience, with VS2010, when include files can't be found at compile time, doing a clean, then build usually fixes the problem. It's not that rare for the editor to be able to open an include file and then the compiler to announce that it can't find that very file, even when it is open on the screen!
If the visual studio says that you miss some file in the current source file folder, there is one solution that i used. Just right click the file you want to add and choose Open Document, if it really doesn't exist, then you should see something like cannot find file in the source file path = "somewhere in your computer", then what you could do is the add your source file into that path first and see if it works.
I had this issue after upgrading to Visual Studio 2019 from 2015. It would compile the project fine but Intellisense and the IDE couldn't find any header files.
The project only had valid configuration for Win32/Debug. Include paths were not setup correctly for other environments. Even though Visual Studio displayed the current environment as Win32/Debug, Intellisense must have been using something else.
Changing the current environment to x64/Release, and then back to Win32/Debug fixed it.
In Visual Studio, click on Project > Rescan Solution as shown below to rebuild the project database.
Here's how I solved this problem.
Go to Project --> Show All Files.
Right click all the files in Solutions Explorer and Click on Include in Project in all the files you want to include.
Done :)
I encountered this issue, but the solutions provided didn't directly help me, so I'm sharing how I got myself into a similar situation and temporarily resolved it.
I created a new project within an existing solution and copy & pasted the Header and CPP file from another project within that solution that I needed to include in my new project through the IDE. Intellisense displayed an error suggesting it could not resolve the reference to the header file and compiling the code failed with the same error too.
After reading the posts here, I checked the project folder with Windows File Explorer and only the main.cpp file was found. For some reason, my copy and paste of the header file and CPP file were just a reference? (I assume) and did not physically copy the file into the new project file.
I deleted the files from the Project view within Visual Studio and I used File Explorer to copy the files that I needed to the project folder/directory. I then referenced the other solutions posted here to "include files in project" by showing all files and this resolved the problem.
It boiled down to the files not being physically in the Project folder/directory even though they were shown correctly within the IDE.
Please Note I understand duplicating code is not best practice and my situation is purely a learning/hobby project. It's probably in my best interest and anyone else who ended up in a similar situation to use the IDE/project/Solution setup correctly when reusing code from other projects - I'm still learning and I'll figure this out one day!
If some soul has scrolled down to this bottom, what worked for me was disabling the Disable Database option i.e. set it to False under Tools|Options|Text Editor|C/C++|Advanced. For some reason, it was set to True for me.
As per docs, if it's set to True
All use of the code browsing database (SDF), all other
Browsing/Navigation options, and all IntelliSense features except for
#include Auto Complete are disabled.
None of the solutions worked for me. Here is what was the issue for me:
(Note discrepancy in build configuration and VC++ Directories (x86 vs x64)
To fix, just changed the build configuration to 'x86':