On Mon, 02 Feb 2004 20:02:02 GMT, "Mike Wahler"
<mkwahler@mkwahler.net> wrote in comp.lang.c++:
[color=blue]
>
> "William Payne" <mikas493_no_s_p_a_m_@student.liu.se> wrote in message
> news:bvm97i$443$1@news.island.liu.se...[color=green]
> > Hello, when using cin.getline() with a char array, how should I specify[/color]
> the[color=green]
> > size (the second parameter of getline)?
> >
> > const int buffer_size = 256;
> > char buffer[buffer_size];
> >
> > std::cin.getline(buffer, std::streamsize(buffer_size));
> > or
> > std::cin.getline(buffer, buffer_size);
> > ?
> >
> > I know, I should use std::string and I usually do, but I still want to[/color]
> know[color=green]
> > the proper way. I am writing a program that will be probably converted to[/color]
> C[color=green]
> > so I ended up with char arrays instead of std::string, and the program[/color]
> uses[color=green]
> > a third-party api which is based on C.[/color]
>
> The C++ standard shows these prototypes:
>
> basic_istream<charT,traits>& getline(char_type* s, streamsize n);
> basic_istream<charT,traits>& getline(char_type* s, streamsize n,
> char_type delim);
>
> so I'd use 'streamsize' type.
>
> But with C, you don't have that type, use 'size_t' to specify
> object sizes or counts. And when calling library functions,
> simply use whatever type the prototype specifies.
>
>
> -Mike[/color]
I disagree here, Mike. Since C++ requires a proper prototype in
scope, the conversion is automatic. The functional-like cast just
adds unnecessary clutter in this case.
My rule is never provide an explicit cast for an implicit automatic
loss-less conversion unless the circumstances are complex enough that
someone reading the code might be mislead.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
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