How to Make NetBeans Treat .cpp Files as C++ Source Code? - c++

While programming in NetBeans, I downloaded all the right compilers. C worked fine for me.
But now that I started working with C++, I realized that while opening a new source file C++ with the extension .cpp the NetBeans goes to the C compilers, and then can't find include such as <iostream> etc.
But when opening the file with the extension .c++ the NetBeans does go to the right directory and does recognize everything C++ related. Is there any way to change that so that the extension .cpp will also go to the right directory?
Thank You!

By default, NetBeans does treat .cpp files as C++ source code. The file extension mappings are configurable, so it is possible that they are different or corrupt on your machine. To change them do the following:
Select Tools->Options
Click the C/C++ category.
Click the Other tab
Verify that "cpp" is in the C++ File Extensions list. If it is missing, add it.
Verify that "cpp" is not in the C File Extensions list. If it is present, remove it.
Click OK
Maybe restart NetBeans

Related

VS code : cannot jump between header file and related cpp file

I have a big c++ project in linux. I try to open this project in VS code in windows using remote ssh. After project loaded, i found it cannot jump between header file and its related cpp files, and also cannot jump to variable definition or implemention.
And i already installed extention c/c++, switcher. But i found right click on a variable, it has only following features. Anyone know how to fix it? This is the first time to use VS code. Thanks!
Have you installed this extension on the remote server:

How do I add header file for a C++ console app in Visual Studio 2017

I'm studying C++ from the book "Programming Principles" 2nd edition by Bjarne Stroustrup. In the book the author encourages students to use a header file from "http://www.stroustrup.com/Programming/std_lib_facilities.h" to build a project in Visual Studio 2017.
However, the instructions on how to use it are unclear.
My questions are:
How do I save the header from the web site (what program)?
What extension?
How do I link it to my project?
How do I enable it up once its linked?
I'm using Windows 7 and VS 2017.
-How do I save the header from the web site (what program)?
It is just a text file. Download it using your web browser. Alternatively, copy the contents to any other text file.
-What extension?
The file extension doesn't matter. In general, C++ uses .h, .hpp, hxx, .H, .hh and other file extensions for header files. It is usually a matter of style. I prefer .hpp. Make sure to be consistent.
-How do I link it to my project?
It is a header file, not a library. You don't need to link anything. The linker shouldn't cause any problems.
-How do I enable it up once its linked?
You don't enable or disable a header file. That doesn't make sense.
Just put the text file into your project directory, and #include it.
Warning: This file is outdated and it won't compile with modern versions of MSVC.
How do I save the header from the web site (what program)?
Load the file in your browser.
Press Ctrl+S
Navigate to the folder where you want to save it
Alternative:
Right click on the link
Click on Save Link As... (or something similar depending on your browser's wording)
Navigate to the folder where you want to save the file.
How do I link it to my project?
In the above steps, you should save the file inside your VS project folder.
How do I enable it up once its linked?
Once you save the file, you use a #include to use it in a .cpp file. Your book should explain more about what #include is for and how to use it.

VS Code unable to detect Standard C++ Libraries

I started using VS Code, and after messing around with it I kind of managed to make it detect Windows and Direct3D SDK's with the c_cpp_properties.json, but I'm failing to make the Standard Library work. So, if I do:
#include <string>
#include <vector>
It throws me an error just like this:
//Include file not found in include path
I've searched all over the web and didn't find any clue, so here I am! Strangely enough, if I just create a new .cpp file in an empty window/editor, it works. But the moment I 'load' the folder that file is in, then it fails. So, this is really driving me crazy.
I'm using Windows 10, with .NET 4.6.2, the 2015 Visual C++ Redist, and the Windows 10 SDK, all blazing new installs from today. My ultimate goal is to port a project I made in VS2013 to GNU/Linux, so I'm trying to make things work step by step.
Thanks a lot beforehand!
EDIT: Compiling with g++ works just fine, even though VS Code complains. This is what happens.
VS Code need to locate the include libraries.
First of all locate where g++ is located. You mentioned that it works fine. It's an .exe file (windows). So you may find g++ directory in path settings. view path variables.
Now after getting g++.exe directory you may easily find a file names string in nearby folders or parent folders. After successfully locating it copy its full path.
Now back in VS Code put cursor over green underline and you should see a bulb. Click it and in the options you will see option Edit "includePath" setting or Update "browse.path" setting. Select it and a file will open named c_cpp_properties.json
Now in that file locate "name": "win32". In the include path option paste the directory name of string file like this and you are good to go.
In vscode go to file>preferences>settings then select edit in settings.json (This can be hard to find, certain settings have this option by them, others do not. There is probably a better way to access this file, but I don't know it)
This will open up the settings.json file, where you can add the line:
"C_Cpp.default.includePath": ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include"]
(or whatever your include path is) This will add that include path for all projects, or only the current workspace depending on if you open the settings.json file for "User Settings" or for "Workspace Settings"

How to compile/use intellisense on miscellaneous files in MSVC

When I open a .cpp file separate of any project in MSVC, the debugging tools are greyed out and intellisense doesn't seem to be parsing the text. Is there a way to make it so when I open an individual .cpp file, I can compile it straight away without having to copy paste the code into a new project?
the debugging tools are greyed out and intellisense doesn't seem to be parsing the text. Is there a way to make it so when I open an individual .cpp file
You can't debug it, because there is no program. One file does not make a program. Project "makes" a program.
Is there a way to make it so when I open an individual .cpp file, I can compile it straight away without having to copy paste the code into a new project?
This won't work, because to compile even one file you might need specific compiler settings (include directories), which are specified within project.
However, you can use "Visual Studio command prompt", locate your file and run cl filename.cpp (filename.cpp is your file) command which will attempt to compile/link single file without specifying extra settings. You won't get assistance from ide in this case, but you might be able to compile it (assuming the file contains trivial program that doesn't need extra settings) and read any errors you get from command prompt.
No, there isn't. The minimum unit Visual Studio can build is a project.

Dev-C++ include file paths FLTK(Fast Light Toolkit)

When I compile and run programs in Bloodshed I save everything into a a folder labeled C++ in my username folder. When I downloaded FLTK, extracted it to the C++ folder, then tried to run a program using header files from FLTK, it was unable to find the files. My guess is that when the compiler looks for the header files it's only looking in the C++ folder, and the FLTK header files are embedded in folders that are inside of the C++ folder.
I googled around for a way to somehow have file paths that include looks into when it looks for the specified header file, but I couldn't find anything. Does anyone with experience using Bloodshed know how to do this?
Most people here probably don't use DevC++, having been warned off it by people like me. DevC++ has lots of problems and is no longer being developed. You should consider
switching to Code::Blocks, which is better in just about every way.
If you have installed FLTK properly, you should now have a program called "fltk-config". That program needs to be in your PATH. You need to edit your project's settings so that the output of "fltk-config --cflags" is added to your list of compiler flags and so that the output of "fltk-config --ldflags" is added to your list of linker flags.