- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在 Windows 中,当您以文本模式从文件(或标准输入)读取字符 \r\n
时,\r
被删除,您只能读取 \n
.
是否有一个标准应该如此?
我能确定这对 Windows 上的任何编译器都是正确的吗?在那些平台上,其他特定于平台的字符组合也会被替换为 \n
吗?
最佳答案
是的,这来自与 C 的兼容性。在 C 文本流中,行由换行符终止。这是程序看到的文本流的内部表示。 I/O 库在内部表示和一些外部表示之间进行转换。
内部表示与平台无关,而文本有不同的特定于平台的约定。这就是在流库中使用文本模式的意义所在;可以编写可移植的文本操作程序,这些程序不必包含一堆 #ifdef
指令即可在不同平台上工作,或者构建自己的独立于平台的文本抽象。
碰巧 C 文本流的内部表示与文本文件的 native Unix 表示相匹配,因为 C 语言及其库起源于 Unix。为了将 C 程序移植到其他平台,添加了文本流抽象,使非 Unix 系统上的文本文件看起来像 Unix 文本文件。
在 ISO/IEC 9899:1999 标准(“C99”)中,我们有这个:
7.19.2 Streams
[...]
A text stream is an ordered sequence of characters composed into lines, each line consisting of zero or more characters plus a terminating new-line character. Whether the last line requires a terminating new-line character is implementation-defined. Characters may have to be added, altered, or deleted on input and output to conform to differing conventions for representing text in the host environment. Thus, there need not be a one-to-one correspondence between the characters in a stream and those in the external representation.
大胆强调我的。 C++ 流是根据 C 流定义的。在 C++ 标准中没有对文本模式与二进制模式的解释,除了一个表,该表将各种流模式标志组合映射到适合作为 fopen
的模式参数的字符串。
关于c++ - 为什么 CR LF 在 Windows 中被更改为 LF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371695/
我正在编写在 Windows 中运行并输出文本文件的代码,该文本文件后来成为 Linux 程序的输入。当给定的文件具有 CR+LF 而不仅仅是 LF 的换行符时,此程序的行为不正确。 我知道我可以使用
我想知道之间的区别(如果可能的话提供示例)CR LF (Windows)、LF (Unix) 和 CR (Macintosh) 换行符类型。 最佳答案 CR和LF是控制字符,分别编码为0x0D(十进制
我们有一个名为 LineFeed.sh 的 shell 脚本文件它执行将换行符( LF )转换为回车+换行符的功能。我们希望通过 windows 中的批处理文件完成相同的操作。是否可以? Linux
我想查询我的表中有多少行包含一个或多个 实例。我想不出正确的语法。我会尝试 LIKE '%%',但我不知道如何指定这些特殊字符。我试过 where mydata REGEXP '%[.CR.][.LF
我必须编写一个功能类似于 dos2unix 的 C 程序。它将所有 CR LF 替换为仅 LF(DOS 格式到 Unix 格式)。所以这是我的方法。每次我读一行时,我通过查找 \0 来搜索数据的结尾,
我有一个 UTF-16 编码的文件,我想用 Windows 行结尾替换 UNIX 行结尾。我不想碰其他任何东西。 有没有linux命令行工具可以搜索两个字节“0A 00”并用四个字节“0D 00 0A
在 Windows 上 #include int main() { putc('A',stdout); putc('\r',stdout); putc('\n',stdout
在 Windows 中,当您以文本模式从文件(或标准输入)读取字符 \r\n 时,\r 被删除,您只能读取 \n. 是否有一个标准应该如此? 我能确定这对 Windows 上的任何编译器都是正确的吗?
我被聘为顾问,与糟糕的内部人员一起工作 DSL被一家大公司使用。 我说糟糕是因为代码行不是用回车符或换行符来结束每行代码,而是用五个字符的 ASCII 字符串 分隔的。 .这些文件有数千“行”长。任
我正在 Windows 10 上开发一个 Unity 3D C# 项目,并开始一个新的存储库,我将其添加到我的 .gitattributes 中。文件: # These files are text
我正在 Linux 平台上编写一个程序,该程序生成的文本文件将不可避免地在 Windows 平台上查看。 现在,将 std::endl 传递到 ostream 中仅为换行符生成 CR 字符。当然,这些
交换换行符(例如通过某些文本编辑器)是否会破坏 javascript 代码? 最佳答案 两个控制字符都是valid line breaks .事实上你甚至不需要换行符。这只是为了更好的可读性。除了在字
在 MS Windows 上,使用 Python 3 的 pyodbc 模块,我正在使用 PostgreSQL。当我使用 PostgreSQL 的 TEXT 数据类型并尝试存储类 UNIX 的 EOL
我正在学习 C,我有以下代码: #include #include #include int main(int argc, char *argv[]) { double x; print
我想强制 Git 在 Windows 下使用 LF 而不是 CR+LF check out 文件。 我检查了两个配置选项,但无法找到正确的设置组合。 我想将所有文件转换为具有 LF 换行符并在文件中保
我是一名 Java 开发人员,我正在使用 Ubuntu 进行开发。该项目是在 Windows 中使用 Eclipse 创建的,它使用 Windows-1252编码。 为了转换为 UTF-8,我使用了
我有一个字符串,我想控制它的字符串内容 是否包含 (CR、LF 或 CRLF)? if (no CR, LF or CF or LF) in string: echo 'no sepator
我有一个包含“unix 风格”行尾的文本文件:每行末尾有一个 0x0A。 我正在编写一个脚本来修改该文件,以向其中添加新内容。这是在 Windows 上运行的 JScript。代码如下所示:
为什么 Firefox 和 Chrome 在 POST 时将 LF 字符替换为 CR+LF? 我写了以下内容作为测试: function lftest() { var linefeed
这与这个问题非常相似: What is the differrence between `* text=auto` and `* text eol=lf` in .gitattributes? 但我特
我是一名优秀的程序员,十分优秀!