当前正在创建头文件,并使用ifndef,define,endif等来创建它。
但是,每次创建它时,Visual Studio Code都会引发错误。
#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
正在显示当前错误:
the #endif for this directive is missing[1,2]
unrecognized preprocessing directive[24,2]
expected a declaration[25,1]
我正在从我从另一个程序制作的标头中复制此标头,但是更改了标头名称和ifndef,所以您会认为不会有问题?
显然,编译器首先抱怨该endif有所欠缺。第一步应该是文件的十六进制转储,以查看其中是否有任何奇怪的字符或缺少换行符。