文件名中是否允许空格? [英] Is Space Allowed in Filename?

查看:861
本文介绍了文件名中是否允许空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到C / C ++编译器支持最长254个字符的长文件名加上扩展名。头文件和源代码文件可以

接受字母字符和数字字符之间的空格吗?使用下划线而不是空间是

最佳做法吗?如果是这样,请解释

为什么。

如果空间存在,您是否希望避免在长

文件名中使用两个双引号?没有它,它将是空间不足。


例如:


#include" GameLoop.h" //有效的文件名,因此C / C ++编译器接受它。

#include" Game_Loop.h" //有效的文件名,因此C / C ++编译器接受它。

#include" Game Loop.h" //它可以有效还是无效?它确实有效。


你推荐哪种#include ......是最佳做法?


布莱恩·帕克夫

I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code files
accept space between alphabet character and numeric character? Is it the
best practice to use underscore instead of space? If so, please explain
why.
Would you prefer to avoid using two double quote marks in the long
filename if space is there? Without it, it would be underspace.

For example:

#include "GameLoop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game_Loop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game Loop.h" // Can it be valid or invalid? It does work.

What do you recommend which #include ... is best practice?

Bryan Parkoff

推荐答案

Bryan Parkoff写道:
Bryan Parkoff wrote:
我看到C / C ++编译器支持最多254个字符的长文件名加上扩展名。头文件和源代码文件可以接受字母字符和数字字符之间的空格吗?


是的。唯一禁止的字符是换行符和双

引号字符。

是否使用下划线而不是空格的最佳做法?


编号没有最佳做法。

如果是这样,请
解释原因。您愿意吗?如果有空格,请避免在长
文件名中使用两个双引号?


嗯?

没有它,它将是空间不足。


嗯?

例如:

#include" GameLoop.h" //有效的文件名,因此C / C ++编译器接受它。
#include" Game_Loop.h" //有效的文件名,因此C / C ++编译器接受它。
#include" Game Loop.h" //它可以有效还是无效?它确实有效。


是的,它是有效的。如果您的文件名为Game< space> Loop.h,那么

< space>指定一个空格字符,那就是你需要的东西

给你的预处理器。

你推荐哪些#include ......是最佳实践?
I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code files
accept space between alphabet character and numeric character?
Yes. The only characters prohibited are the newline and the double
quote character.
Is it
the best practice to use underscore instead of space?
No. There is no "best practice".
If so, please
explain why.
Would you prefer to avoid using two double quote marks in the long
filename if space is there?
Huh?
Without it, it would be underspace.
Huh?

For example:

#include "GameLoop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game_Loop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game Loop.h" // Can it be valid or invalid? It does work.
Yes, it is valid. If your file is named "Game<space>Loop.h", where the
<space> designates a single space character, then that''s what you need to
give your preprocessor.
What do you recommend which #include ... is best practice?




做任何更好的事情。


V



Do whatever feels better.

V


> #include" GameLoop.h" //有效的文件名,因此C / C ++编译器接受它。
> #include "GameLoop.h" // Valid Filename so C/C++ Compiler accepts it.
#include" Game_Loop.h" //有效的文件名,因此C / C ++编译器接受它。
#include" Game Loop.h" //它可以有效还是无效?它确实有效
#include "Game_Loop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game Loop.h" // Can it be valid or invalid? It does work




我建议你使用第一个,因为大多数人都使用

这样做(至少在我的国家)。您可能还想看看在您的工作场所使用了什么(b)如果您正在做的工作?或者看看

什么'以前是在开源项目中完成的。


正如Victor Bazarov告诉你的那样,没有最佳实践这样的东西

但是有一些写作约定,你可以选择使用它们或

不。在我的情况下,我会使用:


#include" gameLoop.h"



I recomend you to use the first one since most of the people are used
to do so (at least in my country). You may also want to see what''s used
to be done in your work place (if it''s work that you are doing) or see
what''s used to be done in open source projects.

As Victor Bazarov told you there is not such a thing as a best practice
but there are some writing conventions and you may chose to use them or
not. In my case I would use :

#include "gameLoop.h"


Victor Bazarov写道:
Victor Bazarov wrote:
Bryan Parkoff写道:
Bryan Parkoff wrote:
是否使用下划线而不是空格的最佳做法?写了
Is it
the best practice to use underscore instead of space?wrote


<没有。没有最佳实践。



No. There is no "best practice".




可能没有,但我建议使用Unix名称:

所有字母都是小写的。这简化了程序员的使用,减少了对程序员的困惑,特别是在多平台项目上工作(Windows - 不区分大小写的FS,Unix - 区分大小写的FS)。

考虑为什么SourceForge.net为所有托管项目使用Unix名称。

其次,你为什么规则命名文件命名为

它很容易使用和设置它是否可预测?


这很清楚:

#include" MyBrownCar.h"

但名字是什么如果单字名称,你会给出:

#include" utils.h"



#include" Utils。 h"


在这种情况下,命名凝聚力可能很容易被打破:

#include" MyBrownCar.h"

#包括utils.h


现在,当我去Unix时,我将使用

#include" Utils.h",类推MyBrownCar.h然后编译器找不到

文件,因为它的名字是uti ls.h.


所有其他变体如

" My_Brown_Car.h"



我的布朗Car.h

会让用法真的很头疼。


如果你说所有文件名都是小写的所有平台上的所有

文件都没有问题。


干杯

-

Mateusz Loskot
http://mateusz.loskot.net



May be there isn''t any but I''d recommend to use Unix names:
all letters lower-case. This simplifies the usage and makes less
confusions for programmers, especially working on multiplatform
projects (Windows - case insensitive FS, Unix - case sensitive FS).
Consider why SourceForge.net uses Unix names for all hosted projects.
Second, what a rule would you define for files naming in order to make
it easy to use and set it predictable?

This is clear:
#include "MyBrownCar.h"
but what name will you give in case of single-word name:
#include "utils.h"
or
#include "Utils.h"

In this case, naming cohesion may be broken easily:
#include "MyBrownCar.h"
#include "utils.h"

Now, when I go to Unix and I will use
#include "Utils.h", by analogy to MyBrownCar.h then compiler won''t find
the file because its name is utils.h.

All other variations like
"My_Brown_Car.h"
or
"My Brown Car.h"
will make the usage a real headache.

If you say "all file names are lower case" there is no problem with all
files on all platforms.

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net


这篇关于文件名中是否允许空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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