Jerry Coffin wrote:
>
>> string s;
>>
>> do
>> {
>> cin>>s;
>
> scanf("%s", s);
Yes, but this leaves room for overflow, while C++ new I/O facilities
together with the other high level facilities are more elegant, safe and
convenient (as far as I have read until now).
> does essentially the same thing, from the viewpoint of the stream. The
> one real difference is attributable to the string -- that it resizes
> itself as needed to accomodate the data being read.
Yes, which is nice, safe and convenient. If string gets more than it can
accommodate it throws a length_error exception. No way for overflow here.
>
>> or even this:
>>
>> char v[4];
>>
>> cin.width(4);
>>
>> cin>> v;
>
> scanf("%3s", s);
>
> or:
>
> fgets(buffer, 4, stdin);
>
> Don't get me wrong: I'm not arguing that iostreams lack advantages --
> only that the things you've cited don't (directly) show much advantage
> for them.
Well, the cin way looks more high level and convenient to me.