VS2010 failing to locate source file - c++

My project has following structure:
Someproject
include
workspace
bin
projectspace
source
I am using MFC for dialog based application. I add a new dialog and add a new class.Header and source files are generated in workspace/projectspace folder. I do exclude from project, move the files to respective location (includes/source) and do Add Existing Items in VS. Now when I add a button click event from dialog, it creates a new source file in includes directory. How to avoid this?

You should not do exclude. Instead, copy the files to the desired location, then remove from the project. Then Add existing from the new location.

Related

Adding a CSV file to a project in Visual Studio

I am working on a project where I have to read in serveral pre-existing CSV (dog.csv, horse.csv, etc.). I want to know how would I add these file into my project so that I may test to see if my print functions work (the code is written in c++). Would I have to copy and paste the files into the debugging folder or would I place it under the test folder of the project?
You can include the files in your project in whatever (sub)folder you wish by using Right click -> Add -> Existing Item. Then, right-click on each file and choose Properties. Set up "Copy to output directory" to "Copy if newer".
Then after build, your files will be copied into the bin/debug folder.
To read the file, you can just use:
System.IO.File.ReadAllText("dog.csv");
Another possible way is to add a file within project, right click and select properties, and then in Copy to Output Directory, select Copy always. This way, csv file will be automatically copied in your debug and release packages too.
string executableLocation = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
string csvLocation= Path.Combine(executableLocation, "file.csv");
Above code will read file location from bin directory where your csv file will be stored.
This link should help guide you how to add CSV files to a project.
If you wanted to do a down and dirty way you could just save the CSV's somewhere on your local machine, and then hard code the file path to that location.
Example:
c:\test\Dog.csv and then set that as a variable for whenever you need to read in the csv file.

copy a existing cpp file in C++

This is a very basic question:
I just want to copy a existing cpp file into a new empty project.
I create a new empty project Test, then add a existing item Main from other folder, but the address of Main is still the original address and we can not see the Main under the Test folder. Even I copy the Main into the Test folder, the Source file can still not see the Main in the visual studio.
Open up windows explorer. Manually copy the file to the project folder. Then add that existing copy to the project.

How do you add a file to an existing project in Codelite?

I've got my workspace, project and a single file currently. I want to add an additional file to my src folder but can't figure out how.
I tried adding a new file to my project folder using ctrl+N and it shows up with my first file when I go to Edit -> Open file. However, it won't show up in my src folder while I've got my workspace/project open; that part is still only showing the original file I created when I made the project.
Right click on the src folder and select Add an existing file

Changing Visual Studio default path for .cpp, .h file

I would like Visual Studio to automatically put my .h file in a folder /ProjectPath/include and my src file in /ProjectPath/src. That way, if I use the "Create class wizard" for instance, it would put the good path by default without me having to change the folder. Anyone know what setting I should change to get this behaviour when I add file ?
Thanks,
Jean-Philippe
You can right click on a folder in solution explorer and go to properties, you need to set the Filter property.
For example the Source Files folder by default has a filter like this in a C++ project: cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx

Cannot open include file "AIUtilities.h": No such file or directory. But it exists?

I have a two projects, AI and Core, which used to hold a circular dependency. I have a CoreUtilities file that I have broken up to remove this dependency, and added the functions I have removed to a new file called AIUtilities(.cpp/.h).
I then went to the piece in my AI project that uses these functions and added #include "AI/AIUtilities.h" and changed the function call from CoreUtilities::Functionname to AIUtilities::Functionname. Upon compile, I recieved the error given in the title.
Why! How can I fix it?
Did you update your project settings with the path to the direcory containing AI/AIUtilities?
Update:
From the solution explorer window, right click on your project and choose "properties" then a new windows "your_project_name property page" will pop up.
In this window on the left pane you'll see a tree. Click on 'Configuration properties' which expands to multiple choices. Continue clicking on 'C/C++' then on General. On the right pane appears multiple properties that affect your project.
Choose the "Additional include directories" property and add the path to your new directory. For instance if your path is : "C:\AI\AIUtilities.h" add the following: "C:\" in the property.
Click on "Aplpy button". Done.
As mentioned in other post, you must consider that moving your project around will break your project settings. Don't forget to update them. Or use either environnement variable to set the root of your project or use the "../../" trick. But personnaly I prefer the former.
You need to ensure that the parent directory of AI is on your header include path. Assuming that your code is laid out like this:
blah/source/
AI/
AIUtilities.h
AIUtilities.cpp
Core/
CoreUtilities.h
CoreUtilities.cpp
So either you need to have the header search path to '/blah/Source' or '..' depending on how your directories are structured.
Note that if you have sub-directories inside each project then this can cause problems with resolving the header search path. In that case set the header search path to $(ProjectDir)\.. .