是ANSI还是编译器依赖? [英] Is it ANSI or is it compiler dependent?

查看:85
本文介绍了是ANSI还是编译器依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< iostream>

int main(){

char buff [3];

std :: cin.getline( buff,3);

std :: cin.getline(buff,3);

std :: cout<< buff<<结束;

}

在命令提示符下输入并输入

1234567

你得到什么输出?

请在回复中包含您的编译器品牌/版本。


问题是:ANSI是否要求在
$之后设置ios :: failbit b $ b第一个getline()还是编译器依赖?我希望输出

是一个空行。我对编译器特别感兴趣

输出''34''。


提前致谢

#include<iostream>
int main() {
char buff[3];
std::cin.getline(buff,3);
std::cin.getline(buff,3);
std::cout << buff << endl;
}
Run at command prompt and input
1234567
what do you get as output?
Please include your compiler make/version in replies.

The question is: Does ANSI require that ios::failbit to be set after
the first getline() or is it compiler dependent? I expect the output
to be an empty line. I''m particularly interested in complilers that
output ''34''.

Thanks in advance

推荐答案

2004年5月8日16:29:08 -0700, ja ****** @ hotmail.com (Canonical Latin)写道:
On 8 May 2004 16:29:08 -0700, ja******@hotmail.com (Canonical Latin) wrote:
#include< iostream>
int main(){
char buff [3];
std :: cin.getline(buff,3);
std :: cin.getline(buff,3);
std :: cout<< buff<< ENDL;


std :: cout<< buff<< std :: endl;

}
在命令提示符下运行并输入
1234567
你得到什么作为输出?
请包括你的编译器make /回答中的版本。

问题是:ANSI是否要求在第一个getline()之后设置ios :: failbit,还是依赖于编译器?我希望输出
是一个空行。我对
输出''34'的编译器特别感兴趣。

提前致谢
#include<iostream>
int main() {
char buff[3];
std::cin.getline(buff,3);
std::cin.getline(buff,3);
std::cout << buff << endl;
std::cout << buff << std::endl;
}
Run at command prompt and input
1234567
what do you get as output?
Please include your compiler make/version in replies.

The question is: Does ANSI require that ios::failbit to be set after
the first getline() or is it compiler dependent? I expect the output
to be an empty line. I''m particularly interested in complilers that
output ''34''.

Thanks in advance




一些数据点给你:


Comeau / libcomo:12

Comeau / Dinkumware :(空行)

MSVC7.1 :(空()空行)

MSVC6 / Dinkumware :(空行)

CodeWarrior 8 :(空行)

Borland 5.5.1 :(空行)

Borland C ++ BuilderX:12

gcc 3.3 :(空行)

Digital Mars:12

Intel 7/8 :(空行)


我预计12。第27.6.1.3/17节确实说如果在检测到尾随分隔符之前缓冲区已填满,则将设置failbit。如果你带走第二个getline电话,输出

一直是12,所以也许

这真的归结为不同版本的getline如果表现如何

他们被称为已经设置的failbit。我怀疑他们没有义务做任何特别的事情,但我还没有在

标准中找到证据。

-leor


-

Leor Zolman --- BD软件--- www.bdsoft.com

C / C ++,Java,Perl和Unix的现场培训

C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html




" Leor Zolman" <乐** @ bdsoft.com>在消息中写道

新闻:ha ******************************** @ 4ax.com ...

"Leor Zolman" <le**@bdsoft.com> wrote in message
news:ha********************************@4ax.com...
一些数据点给你:

Comeau / libcomo:12
Comeau / Dinkumware :(空行)
MSVC7.1: (空行)
MSVC6 :(空行)
MSVC6 / Dinkumware :(空行)
CodeWarrior 8 :(空行)
Borland 5.5.1 :(空行)
Borland C ++ BuilderX:12
gcc 3.3 :(空行)
数字火星:12
英特尔7/8 :(空行)

>我预计12。第27.6.1.3/17节确实说如果在检测到尾随分隔符之前缓冲区已填满,则会设置failbit。如果你取消第二个getline调用,输出
一直是12,所以也许
这真的归结为不同版本的getline如果用failbit调用它们已经设置了。我怀疑他们没有义务做任何特别的事情,但我还没有在标准的
中找到证据。
-leor
Some data points for you:

Comeau/libcomo: 12
Comeau/Dinkumware: (empty line)
MSVC7.1: (empty line)
MSVC6: (empty line)
MSVC6/Dinkumware: (empty line)
CodeWarrior 8: (empty line)
Borland 5.5.1: (empty line)
Borland C++BuilderX: 12
gcc 3.3: (empty line)
Digital Mars: 12
Intel 7/8: (empty line)

I expected "12". Section 27.6.1.3/17 does say that failbit will be set if
the buffer fills up before the trailing delimiter is detected. The output
is consistently 12 if you take away the second getline call, so perhaps
this really boils down to how the different versions of getline behave if
they''re called with failbit already set. I suspect they''re not obliged to
do any particular thing then, but I haven''t located evidence of that in the Standard yet.
-leor




谢谢。我知道以前一定要来,但是如果你可以为我解决另一个问题


#include< iostream>


void fun(int v [2]){


std :: cout<< sizeof(v)<< ENDL; // sizeof(int *)=但这个v不是

类型!


}


int main(){


int v [3] = {};


std :: cout<< sizeof(v)<< - ; // 3 * sizeof(int)= OK v是一种类型。


fun(v);


}
<在32位数据/内存机器上gcc 3.2下的
我得到:12-4


为什么这甚至可以编译? ANSI是否认为类型数组arg'将被忽略?



Thank you. I know this must''ve come up before, but if you may solve another
mystery for me

#include<iostream>

void fun(int v[2]) {

std::cout << sizeof(v) << endl; // sizeof(int*) = But this v is not a
type!

}

int main() {

int v[3]={};

std::cout << sizeof(v) << ''-''; // 3 * sizeof(int) = OK v is a type.

fun(v);

}

under gcc 3.2 on a 32 bit data/memory machine I get: 12-4

Why does this even compile? Does ANSI say that typed array arg''s are to be
ignored?




" Canonical Latin" ; < JA ****** @ hotmail.com>在留言中写道

news:7d ************************** @ posting.google.c om ...

"Canonical Latin" <ja******@hotmail.com> wrote in message
news:7d**************************@posting.google.c om...
#include< iostream>
int main(){char char buff [3];
std :: cin.getline(buff,3);
std :: cin.getline(buff,3);
std :: cout<< buff<<在命令提示符下输入并输入
1234567
你得到什么作为输出?
请在回复中包含你的编译器品牌/版本。

我希望输出为空行。
#include<iostream>
int main() {
char buff[3];
std::cin.getline(buff,3);
std::cin.getline(buff,3);
std::cout << buff << endl;
}
Run at command prompt and input
1234567
what do you get as output?
Please include your compiler make/version in replies.

I expect the output to be an empty line.




我认为buff [0] =''\ 0'的原因是合理的'在第二个

getline()之后,字符数为零,表示没有读取任何
。此行为与C getlen()向后兼容。



The reason I think it is reasonable for buff[0]=''\0'' after the second
getline() is that then the character count is zero indicating that nothing
was read. This behavior is backward compatible with C getlen().


这篇关于是ANSI还是编译器依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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