Reputation: 779
I know a fair amount of Java and Eclipse IDE, but am new to Visual Studio and C++. In Eclipse/Java, if you use a predefined class, Eclipse helpfully suggests the appropriate header file to include for the code to compile. Wondering if Visual Studio has similar functionality.
For example every time I use a code sample from the web, I spend a lot of time Googling which header files to include so the code will compile. My current challenge: I'm writing a small utility that reads filenames in a directory into an array for batch renaming. For this, I'm using following code fragment:
DIR* dir;
struct dirent* dirEntry;
dirEntry = readdir(dir);
Visual Studio is giving the error message: "DIR" is unidentified. "readdir" is unidentified.
Is there an efficient way to locate the appropriate header files for C++ code fragments to resolve error messages like these? Thanks.
Upvotes: 0
Views: 580
Reputation: 779
As mentioned in some answers above, Visual Studio has started offering some suggestions for header files. But as of this writing, some VS suggestions lead to other error messages. E.g. I just used getline()
. VS gave error message: Identifier "getline" is unidentified. It suggested I add using namespace std::basic_istream;
to my code. But this was not applicable to my code and produced additional error messages.
After stumbling around, I found a very simple solution: Visit the C++ reference website. There I searched for getline
and found the header information at the following link: getline(). To fix the error, I needed to #include <string>
.
Upvotes: 1
Reputation: 4017
I tested this feature in vs2019 community 16.3.6 and it works. When you hover the mouse at the location of an error, you can see an error light bulb. And click the drop-down arrow next to the error bulb to add missing #include.
You can also press Alt+Enter.
Upvotes: 1