为什么MSVC ++会给我一个错误,如果我试图将一个头文件编译为一个没有换行符的包含文件? (C ++ /视窗) [英] Why does MSVC++ give my an error if I try to compile a header into an include without a newline? (C++/Windows)

查看:114
本文介绍了为什么MSVC ++会给我一个错误,如果我试图将一个头文件编译为一个没有换行符的包含文件? (C ++ /视窗)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <$ c $我使用MSVC ++编程一个简单的窗口,并且包含一个菜单的资源文件。 c> MYMENU MENU DISCARDABLE 
//等等。

我创建了一个头文件resourcedef.h,定义如

  #define ID_MYMENU_FILE_CLOSE 1002 

我可以将它包含在我的main.cpp文件中,但没有错误,但是,当我将它包含在资源文件中时,我收到错误

  .\resourcedef.h(9):致命错误RC1004:发现意外的文件结尾

(resourcedef.h正好是9行)。当我添加换行符时,.h结尾,

  //第1-8行
#define ID_MYMENU_FILE_OPEN 1001

为了确保第十个空白行(不会出现在SO上)精细。如果我在第十行添加任何内容,即使是评论,编译器也会给我一个错误。有谁知道是什么原因造成的,以及我如何修复它?

解决方案

在末尾省略尾随换行符是个坏主意的文本文件 - 有许多工具无法正常工作,除非它在那里。 (一些文本编辑器甚至会警告你缺少它。)



尾随的换行符是文本文件的标准行为 - 为什么不随流而行呢?每个人都这样做。 8 - )

I'm using MSVC++ to program a simple window, and I included a resource file for a menu along the lines of:

MYMENU MENU DISCARDABLE
//etc.

and I created a header file "resourcedef.h" with definitions like

#define ID_MYMENU_FILE_CLOSE 1002

I can include it in my main.cpp file without error, however, when I include it in the resource file, I get the error

.\resourcedef.h(9) : fatal error RC1004: unexpected end of file found

(resourcedef.h is exactly 9 lines long). When I add a newline the the end of the .h,

//lines 1 - 8
#define ID_MYMENU_FILE_OPEN 1001

So that there is a tenth blank line (that doesn't appear on SO), it compiles fine. If I put anything on the tenth line, even a comment, the compiler gives me an error. Does anyone know what causes this and how I can fix it?

解决方案

It's a bad idea to omit the trailing newline at the end of a text file - there are many tools that will fail to work properly unless it's there. (Some text editors will even warn you that's it's missing.)

Trailing newlines are standard behaviour for text files - why not go with the flow and just put one there. Everybody else does. 8-)

这篇关于为什么MSVC ++会给我一个错误,如果我试图将一个头文件编译为一个没有换行符的包含文件? (C ++ /视窗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆