Reputation: 33
Currently creating a header file, and using the ifndef, define, endif, etc to create it.
However, every time I create it, Visual Studio Code is throwing errors.
#ifndef _roundemup_h_
#define _roundemup_h_
#include <iostream>
#include <fstream>
#include <string>
void file_name(std::ifstream &input)
{
std::string filename;
while (true)
{
std::cout << "Please enter a file name: " << std::endl;
getline(std::cin, filename);
input.open(filename);
if (input.is_open())
{
break;
}
std::cerr << "Unable to Process File." << std::endl;
}
}
#endif
Current errors being show:
the #endif for this directive is missing[1,2]
unrecognized preprocessing directive[24,2]
expected a declaration[25,1]
I'm copying this from a header I've made from another program but have changed the header name and ifndef, so you would think there would be no issue?
Upvotes: 1
Views: 12863
Reputation: 11
I just got this error in visual studio. All I did to fix it is by adding the following line to the end of my header file. #endif // (ClassName_H)
Upvotes: 1
Reputation: 881463
It seems clear that the compiler is first complaining that the endif is somehow deficient. First step should be a hex dump of the file to see if there are any weird characters in there, or a missing newline.
If in Linux, you can use something like:
od -xcb myfile.h
Upvotes: 2