常见问题:文件名中的斜杠??? [英] FAQ: slashes in your filenames???

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

问题描述

为什么faq会在路径中做出关于斜杠的声明:


"这是因为这些操作系统上的库例程

处理 /"

和\互换。

http://www.parashift.com/c++-faq-lit...html#faq-15.16


这似乎完全是错误的答案题。而不是说
说你应该使用正斜杠作为分隔符,它应该说

某事的效果请参考你的操作系统文档如何

指定路径/​​子目录,记住在C ++中的字符串文字中

反斜杠(\)字符修改后面的字符,因此

使用反斜杠作为目录分隔符的操作系统应该是
编码为''\\''。


评论?

解决方案

Julie< ju *** @ nospam.com>这样说:

对于这个问题,这似乎完全是错误的答案。它不应该说你应该使用正斜杠作为分隔符,而是应该说有关如何指定路径/​​子目录的操作系统文档,请记住在C ++中的字符串文字中,反斜杠(\)字符修改了以下字符,因此使用反斜杠作为目录分隔符的操作系统应该被编码为' '\\''。




FWIW,我过去曾被'/ vs \\'问题所困扰。无论是否行为符合要求,我会说使用实现更喜欢的

分隔符会更安全......


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。


Julie写道:

为什么faq会在路径中做出关于斜杠的声明:

这是因为这些操作系统上的库例程处理/"
和\互换。

http://www.parashift.com/c++-faq-lit...html#faq-15.16

对于这个问题,这似乎完全是错误的答案。它不应该说你应该使用正斜杠作为分隔符,而是应该说有关如何指定路径/​​子目录的操作系统文档,请记住在C ++中的字符串文字中,反斜杠(\)字符修改了以下字符,因此使用反斜杠作为目录分隔符的操作系统应该被编码为' '\\''。




使用''/''代替''\\''似乎不太可能/

任何方式伤害/你 - 它应该使代码更便携。对于完整的

可移植性,我不认为你可以假设任何关于目录

分隔符(或者甚至假设有目录,但没有人是

如果您决定只支持支持

目录的系统,可能会抱怨,我认为。


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。


Julie写道:

为什么faq在
路径中发出关于斜杠的声明:

这个是因为这些操作系统上的库例程处理/和/和。互换。

http://www.parashift.com/c++-faq-lit...html#faq-15.16
对于这个问题,这似乎完全是错误的答案。不应该说你应该使用前锋斜杠作为分隔符,而应该说一下参考你的操作系统文档
如何指定路径/​​子目录,记住的效果。在C ++中的字符串文字中,反斜杠(\)字符
修改了以下字符,因此操作使用反斜杠作为目录分隔符的系统
应该被编码为''\\''。

评论?




使用正斜杠非常便携。正如答案

正确陈述的那样,即使是本机使用的操作系统也可以使用

" \ (Windows,DOS,OS / 2等)提供了图书馆例程,

理解/。所以/是非常便携的 - 当然比b / b更优惠



所以我不会称它为完全错误的答案, "但是我会给b $ b添加免责声明,

标准对目录分隔符没有任何保证。事实上,对于一个目录(甚至是一个文件系统)来说,没有什么可以保证



Why does the faq make this statement regarding slashes in paths:

"This is because the library routines
on these operating systems handle "/"
and "\" interchangeably. "

http://www.parashift.com/c++-faq-lit...html#faq-15.16

This seems like completely the wrong answer for this question. Rather than
saying that you should use forward slash as a delimiter, it should say
something to the effect of "refer to your operating system documentation on how
to specify paths/subdirectories, remembering that in a string literal in C++
the back-slash (\) character modifies the following character, and therefore
operating systems that use a backslash as a directory delimiter should be
encoded as ''\\''.

Comments?

解决方案

Julie <ju***@nospam.com> spoke thus:

This seems like completely the wrong answer for this question. Rather than
saying that you should use forward slash as a delimiter, it should say
something to the effect of "refer to your operating system documentation on how
to specify paths/subdirectories, remembering that in a string literal in C++
the back-slash (\) character modifies the following character, and therefore
operating systems that use a backslash as a directory delimiter should be
encoded as ''\\''.



FWIW, I''ve been bitten by / vs. \ issues in the past. Whether or not
that behavior is conforming, I''d say it''s safer just to use the
delimiter that the implementation prefers...

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


Julie wrote:

Why does the faq make this statement regarding slashes in paths:

"This is because the library routines
on these operating systems handle "/"
and "\" interchangeably. "

http://www.parashift.com/c++-faq-lit...html#faq-15.16

This seems like completely the wrong answer for this question. Rather than
saying that you should use forward slash as a delimiter, it should say
something to the effect of "refer to your operating system documentation on how
to specify paths/subdirectories, remembering that in a string literal in C++
the back-slash (\) character modifies the following character, and therefore
operating systems that use a backslash as a directory delimiter should be
encoded as ''\\''.



It doesn''t seem likely that using ''/'' instead of ''\\'' will /hurt/ you in
any way -- and it should make the code a bit more portable. For full
portability, I don''t think you can assume anything about the directory
separator (or even assume that there are directories, but no one is
likely to complain if you decide to only support systems that support
directories, I think).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


Julie wrote:

Why does the faq make this statement regarding slashes in
paths:

"This is because the library routines
on these operating systems handle "/"
and "\" interchangeably. "

http://www.parashift.com/c++-faq-lit...html#faq-15.16
This seems like completely the wrong answer for this
question. Rather than saying that you should use forward
slash as a delimiter, it should say something to the
effect of "refer to your operating system documentation
on how to specify paths/subdirectories, remembering that
in a string literal in C++ the back-slash (\) character
modifies the following character, and therefore operating
systems that use a backslash as a directory delimiter
should be encoded as ''\\''.

Comments?



Using the forward slash is very portable. As the answer
correctly states, even operating systems that natively use
"\" (Windows, DOS, OS/2, etc.) provide library routines that
understand "/". So the "/" is very portable -- certainly
better than "\".

So I wouldn''t call it "completely the wrong answer," but I
would add a disclaimer that nothing is guaranteed by the
standard about directory delimiters. In fact, nothing is
guaranteed about a directories (or even a filesystem)
existing at all.


这篇关于常见问题:文件名中的斜杠???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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