Eclipse CDT "New Class" default paths for created source files - c++

How can I configure Eclipse 4.2 to put the test file in tests/ when using the New Class wizard?

I'm looking for the same thing... well, I was looking to automate it. In the remote case you didn't figure out any solution at all, here's my solution that is a 2 extra clicks and some typing (steps 3 and 4).
Right click folder you want your new source files (.h and .cpp) to be in, and choose create new class
Type the 'class name' as usual, check 'unit test'
Click Browse next to unit test and click ok, without selecting a file (but don't hit cancel!).
choosing a path doesn't do anything. It would be nice if Eclipse would append the path to the file name, but it doesn't.
What it does do is change the source folder to the project root, and fills in a relative path for the other 2 files, src/class.h and src/class.cpp.
Type test/ in front of the test file name to specify the path.

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.

Open files in NetBeans 8.0.2 are kept in the project file thus making it dirty in GIT

I've been using NetBeans for the last couple of years and only recently upgraded to 8.0.2. It seems that the new project file tracks which files are open in the project workspace (C++) and thus the project file appears as modified whenever I open Netbeans, although I haven't changed anything. Is there a setting to disable this?
Create a file named ".gitignore" in the top-level directory, if it does not
already exist.
Add the line:
nbproject/private/
To do this with Netbeans:
Window -> Files, Select the Directory and right-click for Pop-up.
New -> Other ... -> Empty File.
Name the file ".gitignore"
When you do diffs and commits etc. it should ignore the private files that might have changed.

Sublime Text 2 FileTemplates plugin doesn't work

I want to use "FileTemplates" plugin in Sublime Text 2. I installed it with Package Controller, but when I use "Create file from template" and select something, nothing happens! It doesn't even create a file.
How can I make it work? Any ideas?
You need to find you current user's packages folder. Here you will find where the FileTemplates package has been installed. On my Windows system it is %APPDATA%\Roaming\Sublime Text 2\Packages\FileTemplates. You may also get to this folder from the Preferences menu by selecting Browse Packages...
Inside this folder there is a Templates folder. Inside this folder you will find the pre-canned file templates. You may create your own by copying and pasting the existing files to create the templates you like. You will need to create a .file-template file in the FileTemplates folder. This file is an xml file which tells sublime where to find the actual template and what parameters to the file creation the user may pass into the template. For instance $name is the parameter that the user is prompted for which will be used to name the file created from the template. Hope this helps.

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)\.. .