468,463 Members | 1,959 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

How to use lib function "getline"

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?
Aug 20 '06 #1
33 24686
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

Aug 20 '06 #2
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
Aug 20 '06 #3
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.
Aug 20 '06 #4
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?

You have to find the header file that has the
prototype of the "getline" function.

This is a common problem for beginners, and it is easily solved.
Just look for the documentation of your getline function.
Under Unix this happens mostly with

man getline

or

info getline

Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.
Aug 20 '06 #5

"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr...
Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.
I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h". But now it is not there. My IDE is DEV-C++.And do not have a
reference for "getline". Could you tell me what is your IDE?
Aug 20 '06 #6
Default User wrote:
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.
It appears to me that both you and I are guessing at
what the original poster's problem is. It could be that
your guess is correct and mine isn't but unless Chen
elaborates you can't be sure what the correct redirection
is.

And needless to say that I don't offer suggestions unless
I believe (perhaps mistakenly) that I understand the
problem.

Aug 20 '06 #7
Chen shuSheng wrote:
"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr...

>>Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.


I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h". But now it is not there. My IDE is DEV-C++.And do not have a
reference for "getline". Could you tell me what is your IDE?

Dev C++ is a really bad quality IDE. It delivers nothing like
really good help system...

If you want to go on with C instead of using C++ you can
just do:

#include <stdio.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
fgets(line,max,stdin);
system("PAUSE");
return 0;
}
Aug 20 '06 #8


"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr...
Chen shuSheng wrote:
>"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr.. .

>>>Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.


I have a reference book "C/C++ lib" which tells me that this pototype is
in "iostream.h". But now it is not there. My IDE is DEV-C++.And do not
have a reference for "getline". Could you tell me what is your IDE?
Dev C++ is a really bad quality IDE. It delivers nothing like
really good help system...
Could you recommend a IDE for C?
Aug 20 '06 #9
"Chen shuSheng" <cs*****@gmail.comwrites:
I have a code:
---------------------------
#include <iostream.h>
This is not a standard C header. (C++, maybe?)
#include <stdlib.h>

int main()
Better: "int main(void)".
{ int max=15;
char line[max];
This is a variable-length array. This is standard in C99, but not all
compilers support it.

<OT>It's also standard in C++, but if you're trying to write a C++
program you should ask in comp.lang.c++.</OT>
getline(line,max);
There is no "getline" function in standard C.
system("PAUSE");
This is not portable; many systems don't have an external command
called "PAUSE".
return 0;
}
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #10
Chen shuSheng schrieb:
"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr...

I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h". But now it is not there.
Jacob already answered the rest of your question.
There are two languages, C and C++. Parts of C++ _look_ similar
to C and C++ defines its relationship to C with respect to
linkage. Do not mix the two of them unless you know exactly what
you are doing.

The C++ standard library incorporates the C90 standard library
but by other header names in order to disambiguate between C
and C++ headers.

You obviously got information about a method of a C++ class,
not a function. You probably would have to use it like
cin.getline() or something like that. As it is C++, you
ought to ask for advice in comp.lang.c++ if you want to write
C++.

If you want to write C, then there is no standard C library
function getline() and you can go with fgets() or ggets() as
I mentioned elsethread if you want to stay on the safe side.
Or, if you want to use getline(), you have to obtain it from
somewhere and use it according to its documentation.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 20 '06 #11
Keith Thompson wrote:
"Chen shuSheng" <cs*****@gmail.comwrites:
>>I have a code:
---------------------------
#include <iostream.h>


This is not a standard C header. (C++, maybe?)

>>#include <stdlib.h>

int main()


Better: "int main(void)".

>>{ int max=15;
char line[max];


This is a variable-length array. This is standard in C99, but not all
compilers support it.

<OT>It's also standard in C++, but if you're trying to write a C++
program you should ask in comp.lang.c++.</OT>
No, it's an error in C++, where VLAs are absent.

--
Ian Collins.
Aug 20 '06 #12

"Keith Thompson" <ks***@mib.org??????:ln************@nuthaus.mib.or g...
program you should ask in comp.lang.c++.</OT>
> getline(line,max);

There is no "getline" function in standard C.
I see this function in K&R classic "The C programming language". All code
are below.
-----------
#include <ctype.h>
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#define MAXLINE 100
/* rudimentary calculator */
/* atof: convert string s to double */
double atof(char s[]);

int main(void)
{
double sum;
char line[MAXLINE];
int getline(char line[], int max);
sum = 0;
while(getline(line,MAXLINE)0)
printf("\t%g\n", sum += atof(line));
return 0;
}

double atof(char s[])
{
double val, power;
int i, sign;
for (i = 0; isspace(s[i]); i++); /* skip white space */
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-')
i++;
for (val = 0.0; isdigit(s[i]); i++)
val = 10.0 * val + (s[i] - '0');
if (s[i] == '.')
i++;
for (power = 1.0; isdigit(s[i]); i++) {
val = 10.0 * val + (s[i] - '0');
power *= 10;
}
return sign * val / power;
}
---------------
That is why I assume "getline" could be find somewhere in C.Also your name
is alike originator of this book. And I confused right now with thinking I
see the author.
After you test this code, you will find a message: "no reference of
getline". Is it the author writing a wrong code?
Aug 20 '06 #13
"Chen shuSheng" <cs*****@gmail.comwrites:
"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr...
>Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.

I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h". But now it is not there. My IDE is DEV-C++.And do not have a
reference for "getline". Could you tell me what is your IDE?
I wouldn't trust anything with "C/C++" in the title. C and C++ are
two different languages. Decide which language you want to use. If
your book is that unclear about the difference, get a better book.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #14
Chen shuSheng wrote:
"Keith Thompson" <ks***@mib.org??????:ln************@nuthaus.mib.or g...
>>program you should ask in comp.lang.c++.</OT>
>> getline(line,max);

There is no "getline" function in standard C.


I see this function in K&R classic "The C programming language". All code
are below.
-----------
#include <ctype.h>
#include <stdio.h>
#include <iostream.h>
This is an obsolete C++ header, why are you using it in what is supposed
to be C?

--
Ian Collins.
Aug 20 '06 #15

"Ian Collins" <ia******@hotmail.com??????:4k************@individ ual.net...
>#include <ctype.h>
#include <stdio.h>
#include <iostream.h>

This is an obsolete C++ header, why are you using it in what is supposed
to be C?

--
Ian Collins.
Sorry, "#include <iostream.h>" is added by me. Because I debug this program.
Without that, Have a look again.
Aug 20 '06 #16
Ian Collins <ia******@hotmail.comwrites:
Keith Thompson wrote:
[...]
><OT>It's also standard in C++, but if you're trying to write a C++
program you should ask in comp.lang.c++.</OT>
No, it's an error in C++, where VLAs are absent.
D'oh! That will teach me not to post off-topic information.

(No, it probably won't.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #17
Chen shuSheng wrote:
"Keith Thompson" <ks***@mib.org??????:ln************@nuthaus.mib.or g...
>>program you should ask in comp.lang.c++.</OT>
>> getline(line,max);

There is no "getline" function in standard C.


I see this function in K&R classic "The C programming language". All code
are below.
Look back a couple of pages, you will see getline was the previous example!

--
Ian Collins.
Aug 20 '06 #18
"Chen shuSheng" <cs*****@gmail.comwrites:
"Keith Thompson" <ks***@mib.org??????:ln************@nuthaus.mib.or g...
>program you should ask in comp.lang.c++.</OT>
>> getline(line,max);

There is no "getline" function in standard C.

I see this function in K&R classic "The C programming language". All code
are below.
I don't have my copy of K&R handy at the moment, but ...
-----------
#include <ctype.h>
#include <stdio.h>
#include <iostream.h>
Once again, there is no <iostream.hheader in standard C, and I don't
believe there's any mention of it in K&R.
#include <stdlib.h>
#define MAXLINE 100
/* rudimentary calculator */
/* atof: convert string s to double */
double atof(char s[]);

int main(void)
{
double sum;
char line[MAXLINE];
int getline(char line[], int max);
This is a declaration of a function called "getline", but there's no
definition for it. If this appeared in an example in K&R, there would
be a definition for the getline function, possibly in a separate file
(though in that case I'd expect the declaration to be in a header).

[snip]
---------------
That is why I assume "getline" could be find somewhere in C.
Not unless you write it yourself.
Also your name is alike originator of this book. And I confused
right now with thinking I see the author.
The book you mentioned, K&R, was written by Brian Kernighan and Dennis
Ritchie. Ken Thompson is another author who has worked with both of
them. I'm not related to him.
After you test this code, you will find a message: "no reference of
getline". Is it the author writing a wrong code?
The code you posted uses a non-standard "getline" function without
defining it. I don't believe that mistake exists in K&R.

Incidentally, *please* indent your code; it's very difficult to read
otherwise.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #19
Default User wrote:
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.
No it isn't, its an extension in the gnu C library.
Please don't give redirects
unless you are ACTUALLY familiar with the problem.
We all do your best :-)
>
The correct group is comp.lang.c++.
I believe comp.unix.programmer and comp.os.linux.development.apps
are correct.

goose,

Aug 20 '06 #20
Chen shuSheng wrote:
I have a code:
---------------------------
#include <iostream.h>
<iostream.his not a standard C header. The similarity between
<iostream.hand the name of a C++ header, <iostream>, suggests that you
may be trying to write C++. Note
1) C and C++ are different languages. C++ has its own newsgroup
<news:comp.lang.c++>
2) Both the C and C++ newsgroups have FAQs. It is impolite to post to a
newsgroup without checking the FAQ first.
3) Both the C and C++ newsgroups are archived at Google groups. It is
impolite to post to a newsgroup without following it for while. This
can be done in something close to real time (as we did in the old days)
or much more quickly with the Google group archives.
4) Before posting to <news:comp.lang.c++) learn enough C++ so you don't
blunder with <iostream.hwhen the C++ standard header is <iostreamor
with <stdlib.hwhen the C++ standard header is <cstdlib>.
#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?
There is no function getline() in C and you need to learn about using
namespaces if your are going to write in C++. Do so before posting to
<news:comp.lang.c++(and don't post anything about C++ here).
Aug 20 '06 #21
goose wrote:
Default User wrote:
>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.


No it isn't, its an extension in the gnu C library.
<OT>Nonsense, it's a couple of standard functions.</OT>

--
Ian Collins.
Aug 20 '06 #22
Keith Thompson <ks***@mib.orgwrites:
"Chen shuSheng" <cs*****@gmail.comwrites:
>"Keith Thompson" <ks***@mib.org??????:ln************@nuthaus.mib.or g...
That is why I assume "getline" could be find somewhere in C.

Not unless you write it yourself.
>Also your name is alike originator of this book. And I confused
right now with thinking I see the author.

The book you mentioned, K&R, was written by Brian Kernighan and Dennis
Ritchie. Ken Thompson is another author who has worked with both of
them. I'm not related to him.
>After you test this code, you will find a message: "no reference of
getline". Is it the author writing a wrong code?

The code you posted uses a non-standard "getline" function without
defining it. I don't believe that mistake exists in K&R.
On page 70 of the original K&R, getline() is used in code. Flipping
back to page 68, the line "cc main.c getline.o index.o" is shown,
indicating that getline has indeed been defined... one page 26.

Perhaps the OP should learn how to read his index, or perhaps he
should purchase a newer version of K&R.

--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 20 '06 #23
On 20 Aug 2006 01:13:41 -0700, sp****@gmail.com wrote in comp.lang.c:
Default User wrote:
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.

It appears to me that both you and I are guessing at
what the original poster's problem is. It could be that
your guess is correct and mine isn't but unless Chen
elaborates you can't be sure what the correct redirection
is.

And needless to say that I don't offer suggestions unless
I believe (perhaps mistakenly) that I understand the
problem.
Actually, I think the <iostream.hmoves the other guess into the
range of extremely high probability.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Aug 20 '06 #24
goose <lk***@webmail.co.zawrites:
Default User wrote:
>sp****@gmail.com wrote:
[...]
>>>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.

No it isn't, its an extension in the gnu C library.
It's a floor cleaner *and* a dessert topping!

getline is a function (method?) in the C++ strings library, *and* a
GNU extension to the standard C library, *and* a function implemented
as an example in K&R. (I think the latter is the only one that's
relevant here.)

It's also an ordinary unreserved identifier; any C program is free to
define it any way it likes (but, as with any other identifier, you
have to be careful of naming conflicts).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #25
sp****@gmail.com wrote:
Default User wrote:
sp****@gmail.com wrote:
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.

It appears to me that both you and I are guessing at
what the original poster's problem is. It could be that
your guess is correct and mine isn't but unless Chen
elaborates you can't be sure what the correct redirection
is.
Yes. His later posts do indicate that he is trying some out of date
C++, but I have been edumacated that getline() is also a gcc extension.
And needless to say that I don't offer suggestions unless
I believe (perhaps mistakenly) that I understand the
problem.
Sure. I was overly grumpy.

Brian
Aug 20 '06 #26
goose wrote:
Default User wrote:
sp****@gmail.com wrote:
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.

No it isn't, its an extension in the gnu C library.
It is both, although the C++ version has a different signature.
The correct group is comp.lang.c++.
I believe comp.unix.programmer and comp.os.linux.development.apps
are correct.
Subsequent messages from the OP seem to indicate that he was trying to
use outdated C++ (iostream.h) functionality.

Brian
Aug 20 '06 #27
"Default User" <de***********@yahoo.comwrites:
goose wrote:
>Default User wrote:
sp****@gmail.com wrote:
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.

No it isn't, its an extension in the gnu C library.

It is both, although the C++ version has a different signature.
The correct group is comp.lang.c++.
I believe comp.unix.programmer and comp.os.linux.development.apps
are correct.

Subsequent messages from the OP seem to indicate that he was trying to
use outdated C++ (iostream.h) functionality.
Yes, but I think the getline() function he was trying to use was
actually one presented as an example in K&R.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #28
Default User wrote:
sp****@gmail.com wrote:
It appears to me that both you and I are guessing at
what the original poster's problem is. It could be that
your guess is correct and mine isn't but unless Chen
elaborates you can't be sure what the correct redirection
is.

Yes. His later posts do indicate that he is trying some out of date
C++, but I have been edumacated that getline() is also a gcc
extension.
And it then turns out he was really talking about neither, exactly.

Brian (exceedling sorry he ever got involved)

Aug 20 '06 #29
On Sun, 20 Aug 2006 16:09:26 +0800, in comp.lang.c , "Chen shuSheng"
<cs*****@gmail.comwrote:
>
"jacob navia" <ja***@jacob.remcomp.fr>
??????:44*********************@news.orange.fr.. .
>Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.

I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h".
Hopefully it also mentions that "iostream.h is a C++ header, and
therefore not usable in C.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 20 '06 #30
Default User wrote:
Default User wrote:
<snipped>
>>Yes. His later posts do indicate that he is trying some out of date
C++, but I have been edumacated that getline() is also a gcc
extension.
Similarly, I've been informed that getline is some
damn C++ "thingy" :-(
>
And it then turns out he was really talking about neither, exactly.

Brian (exceedling sorry he ever got involved)
At this point, you're not the only sorry one.

goose,
ambiguity is the route of all evil :-)
Aug 20 '06 #31
jacob navia wrote:
>
.... snip ...
>
Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.
No you don't. I virtually never use any sort of IDE under
windows. I do use both info and man under windows. However none
of these would ever show getline as a standard, because it just
isn't. It is whatever you define it to be.

--
Chuck F (cb********@yahoo.com) (cb********@maineline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.netUSE maineline address!

Aug 20 '06 #32
Keith Thompson wrote:
"Default User" <de***********@yahoo.comwrites:
Subsequent messages from the OP seem to indicate that he was trying
to use outdated C++ (iostream.h) functionality.

Yes, but I think the getline() function he was trying to use was
actually one presented as an example in K&R.
Indeed. As I said in another reply, I sincerely wish I'd never got
involved. Especially as I redirected to clc++ and had to post an answer
over there.

Brian (sadder but wiser)
Aug 21 '06 #33
On Sun, 20 Aug 2006 20:34:43 +1200, Ian Collins <ia******@hotmail.com>
wrote:
Keith Thompson wrote:
"Chen shuSheng" <cs*****@gmail.comwrites:
>{ int max=15;
char line[max];

This is a variable-length array. This is standard in C99, but not all
compilers support it.

<OT>It's also standard in C++, but if you're trying to write a C++
program you should ask in comp.lang.c++.</OT>
No, it's an error in C++, where VLAs are absent.
<OTVLAs are absent, but constant expressions are defined
differently. The example given is indeed illegal in C++, but
{ const int max = 15; char line[max]; ... }
is legal in C++(98).

- David.Thompson1 at worldnet.att.net
Aug 28 '06 #34

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.