c form响应回车_C ++标准(源文件的换行符结尾)

I am referring to: Why should text files end with a newline?

One of the answers quotes the C89 standard. Which in brief dictates that a file must end with a new line, which is not immediately preceded by a backslash.

Does that apply to the most recent C++ standard?

#include

using namespace std;

int main()

{

cout << "Hello World!" << endl;

return 0;

}

//\

Is the above valid? (Assuming there is a newline after //\, which I've been unable to display)

解决方案

The given code is legal in the case of C++, but not for C.

Indeed, the C (N1570) standard says:

Each instance of a backslash character (\) immediately followed by a new-line

character is deleted, splicing physical source lines to form logical source lines.

Only the last backslash on any physical source line shall be eligible for being part

of such a splice. A source file that is not empty shall end in a new-line character,

which shall not be immediately preceded by a backslash character before any such

splicing takes place.

The C++ standard (N3797) formulates it a bit differently (emphasis mine):

Each instance of a backslash character (\) immediately followed by a new-line character is deleted,

splicing physical source lines to form logical source lines. Only the last backslash on any physical

source line shall be eligible for being part of such a splice. If, as a result, a character sequence that

matches the syntax of a universal-character-name is produced, the behavior is undefined. A source file

that is not empty and that does not end in a new-line character, or that ends in a new-line character

immediately preceded by a backslash character before any such splicing takes place, shall be processed

as if an additional new-line character were appended to the file.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值