c++ - 该指令的 #endif 丢失

标签 c++

当前正在创建一个头文件,并使用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]

我是从我从另一个程序制作的 header 中复制这个,但更改了 header 名称和 ifndef,所以您会认为不会有问题吗?

最佳答案

很明显,编译器首先提示 endif 存在某种缺陷。第一步应该是文件的十六进制转储,以查看其中是否有任何奇怪的字符,或者是否缺少换行符。

如果在 Linux 中,您可以使用类似的东西:

od -xcb myfile.h

关于c++ - 该指令的 #endif 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58295142/

相关文章:

c++ - 将字符串文字传递给采用 std::string& 的函数

c++ - 使用boost python编译在python代码内部调用的c++代码时出错

c++ - 将语言标准应用于源文件的一部分?

c++ - 使用 superres 从多个图像创建超分辨率图像

c++ - 未命名的命名空间与私有(private)变量

c++ - 'short' 在 C++ 中的用法

c++ - 中断可以这样编程吗?

c++ - 编译器错误 : does not name a type

c++ - 强制 CMake/VisualStudio 使用 Boost.Python 的静态库

c++ - 我可以从 opengl 的显示屏上调用我的回调函数吗