gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:08:25 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com