如何使用lib函数“getline” [英] How to use lib function "getline"

查看:91
本文介绍了如何使用lib函数“getline”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码:

---------------------------

#include< iostream.h>

#include< stdlib.h>


int main()

{ int max = 15;

char line [max];

getline(line,max);

system(" PAUSE");

返回0;

}

---------------------

但它不能通过编译器。编译器的消息是隐含的

函数声明''int getline(....)''

你能帮忙让它运行吗?

解决方案

陈树生写道:


我有一个代码:

- -------------------------

#include< iostream.h>

# include< stdlib.h>


int main()

{int max = 15;

char line [max] ;

getline(行,最大);

系统(PAUSE);

返回0;

}

---------------------

但它不能通过编译器。编译器的消息是隐含的

函数声明''int getline(....)''

你能帮忙让它运行吗?



getline()不是标准C因此超出了主题。

你应该问comp.unix.programmer或

comp.os.linux.development.apps


sp **** @ gmail.com 写道:


Chen shuSheng写道:


我有一个代码:

---------------------------

#include< iostream.h>

#include< stdlib.h>


int main()

{int max = 15;

char line [max];

getline(line,max);

system(" PAUSE");


getline()不是标准C因此超出了主题。

你应该问comp .unix.programmer或

comp.os.linux.development.apps



但是,它是一个标准的C ++函数。请不要给重定向

,除非你实际上对这个问题很熟悉。


正确的组是comp.lang.c ++。



Biran


陈树生schrieb:


我有代码:

---------------------------

#include< iostream.h>



< iostream.his不是标准的C头。

< OT>它甚至不是标准的C ++标题; < iostreamis。

如果你尝试一起使用C和C ++,请在comp.lang.c ++中询问;

在这种情况下,你不会#include< stdlib .hbut

< cstdlib>< / OT>


#include< stdlib.h>

int main()



int main(void)

在这里更加明确和首选。


{int max = 15;

char line [max];

getline(line,max);



getline()不是标准的C函数。 glibc提供它

作为< stdio.h>的扩展名。但是,原型确实

与您的使用不符。完全没有。


system(" PAUSE");



这样就无法保证可重现的结果

跨系统甚至在同一系统上的实现。


返回0;

}

---------------------

但它不能通过编译器。编译器的消息是隐含的

函数声明''int getline(....)''



编译器的优点。

由于getline()未知,因为

范围内没有原型,编译器假设(通过旧的隐式int规则)

函数返回int。

通过在系统中包含给getline()提供

的标题来获取范围内的原型。查看getline的用法。

你的用法表明你宁愿满足于

fgets()或非标准的ggets(),例如,

可以从Chuck Falconer的页面获得:
http://cbfalconer.home.att.net/download/

它属于公共领域,用标准C编写。

干杯

Michael

-

电子邮箱:我的是/ at / gmx / dot / de地址。


I have a code:
---------------------------
#include <iostream.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
getline(line,max);
system("PAUSE");
return 0;
}
---------------------
But it can not pass the complier. Message of complier is implicit
declararion of function ''int getline(....)''
Could you help to let it run?

解决方案

Chen shuSheng wrote:

I have a code:
---------------------------
#include <iostream.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
getline(line,max);
system("PAUSE");
return 0;
}
---------------------
But it can not pass the complier. Message of complier is implicit
declararion of function ''int getline(....)''
Could you help to let it run?

getline() is not standard C therefore out of topic here.
You should ask at comp.unix.programmer or
comp.os.linux.development.apps


sp****@gmail.com wrote:

Chen shuSheng wrote:

I have a code:
---------------------------
#include <iostream.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
getline(line,max);
system("PAUSE");

getline() is not standard C therefore out of topic here.
You should ask at comp.unix.programmer or
comp.os.linux.development.apps


However, it is a standard C++ function. Please don''t give redirects
unless you are ACTUALLY familiar with the problem.

The correct group is comp.lang.c++.


Biran


Chen shuSheng schrieb:

I have a code:
---------------------------
#include <iostream.h>

<iostream.his not a standard C header.
<OT>It is not even a standard C++ header; <iostreamis.
If you try to use C and C++ together, ask in comp.lang.c++;
in this case, you would not #include <stdlib.hbut
<cstdlib></OT>

#include <stdlib.h>

int main()

int main (void)
is a little bit more explicit and preferred around here.

{ int max=15;
char line[max];
getline(line,max);

getline() is not a standard C functions. glibc offers it
as extension for <stdio.h>. However, the prototype does
not match your usage. At all.

system("PAUSE");

This gives you no guaranteedly reproducible results
across systems or even implementations on the same system.

return 0;
}
---------------------
But it can not pass the complier. Message of complier is implicit
declararion of function ''int getline(....)''

Good of the compiler.
As getline() is not known because there is no prototype in
scope, the compiler assumes (via the old implicit int rule)
that the function returns int.
Get a prototype in scope by including the header that gives
you getline() on your system. Look up the usage of getline.
Your usage suggests that you would rather be content with
fgets() or the non-standard ggets() which, for example, can
be obtained from Chuck Falconer''s page:
http://cbfalconer.home.att.net/download/
It is in the public domain and written in standard C.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


这篇关于如何使用lib函数“getline”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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