11 Replies - 6940 Views - Last Post: 08 September 2012 - 04:43 PM

#1 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Is something missing in the way C++ stream I/O is taught?

Posted 02 September 2012 - 12:17 PM

Is something missing in the way C++ stream I/O is being taught?

Often there are questions posted here where students are caught in situations where they are wondering why their cin >> foo; calls aren't working because the previous input had left a CR in the input buffer; or their while (!infile.eof()) {...} seemingly duplicating the last input.

If these are common pitfalls, shouldn't books that teach C++ cover these areas? Or such topics deliberately not covered as a rite of passage for beginning C++ students to discover on their own, or ask here on DIC?

Is This A Good Question/Topic? 0
  • +

Replies To: Is something missing in the way C++ stream I/O is taught?

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4232
  • View blog
  • Posts: 13,281
  • Joined: 25-December 09

Re: Is something missing in the way C++ stream I/O is taught?

Posted 02 September 2012 - 12:49 PM

Quote

Is something missing in the way C++ stream I/O is being taught?

In my opinion, yes. I doubt that most books cover the C++ stream error states much at all. For example many students don't realize that entering a character for a numeric variable will cause the stream to enter an error state. They also don't seem to know how to determine the cause or how to clear the error.

Quote

because the previous input had left a CR in the input buffer

Actually this happens most frequently with getline() but does also happen when you are trying to extract to a character. But it seems like either students are not told about this issue or they were asleep when it was mentioned, probably in passing.

Quote

or their while (!infile.eof()) {...} seemingly duplicating the last input.

I have seen so many books use eof() improperly that it is no wonder why so many students improperly use this construct. Also finding a book that actually shows using the stream read operation while(infile >> test) {...} in your loop is almost impossible.

Quote

If these are common pitfalls, shouldn't books that teach C++ cover these areas?

In my opinion yes. But, I know it is hard to cover everything in a single book or class. And I also think students tend to be a little impatient at times and want to dive right into programming without actually reading the text.

Jim
Was This Post Helpful? 2
  • +
  • -

#3 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 10:06 AM

one really good book that I recommend to beginners is "programing: principles and practice using c++". It shows input using while(cin >> x) {...} and later explains error states. most places don't use it though :/

my school's C++ class doesn't even cover templates...I highly doubt they cover the details of IO streams. On top of that, there are only a few classes that even use C++ at my school; most use C# or Java. no one is coming out knowing really anything about C++

I'm quite disappointed with how C++ is taught.

This post has been edited by ishkabible: 03 September 2012 - 10:15 AM

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4232
  • View blog
  • Posts: 13,281
  • Joined: 25-December 09

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 10:58 AM

Quote

I'm quite disappointed with how C++ is taught.

Have you expressed your disappointment to the Dean of Students (or whatever his title is at your university), in writing?

Until the students, their parents, and the business community start to actively complain to the "powers" about the substandard education nothing will ever change.


Jim
Was This Post Helpful? 0
  • +
  • -

#5 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1156
  • View blog
  • Posts: 2,538
  • Joined: 05-May 05

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 02:23 PM

Quote

Often there are questions posted here where students are caught in situations where they are wondering why their cin >> foo; calls aren't working because the previous input had left a CR in the input buffer; or their while (!infile.eof()) {...} seemingly duplicating the last input.


I think it's because C++ novices tend to view I/O streams as magical "do all" abstractions that will fix erroneous situations if need be, instead of viewing them as simple byte buffers. They simply overlook the fact that they need pay attention to things on the byte level.

This post has been edited by blackcompe: 03 September 2012 - 02:37 PM

Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 02:57 PM

The way I was taught C++ I/O was our teacher guided us in examining and taking apart the underlying ios_base class first and then worked our way down the hierarchy. It made us understand how things work, but it was brutal. Like learning gross anatomy complete with cadaver dissection when the objective was to just to teach high school level anatomy.
Was This Post Helpful? 0
  • +
  • -

#7 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 06:12 PM

Hey Skidiver, how about writing a book/tutorial about C++ I/O stream, since you are unhappy with the existing ones? Many people will benefit from it :)

And I am serious, you should write one.
Was This Post Helpful? 0
  • +
  • -

#8 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1102
  • View blog
  • Posts: 4,597
  • Joined: 09-June 09

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 08:54 PM

Quote

ey Skidiver, how about writing a book/tutorial about C++ I/O stream, since you are unhappy with the existing ones? Many people will benefit from it

A book seem's a little unecessary; however, I could see a long article/tutorial being beneficial. Since I was one of the ignorant students that saw iostream as a magical abstraction
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: Is something missing in the way C++ stream I/O is taught?

Posted 03 September 2012 - 10:44 PM

For some of those who want to see some of the nitty gritty parts of the C++ I/O streams, this post covers some of the interesting middle levels to achieve the objective of building a custom stream: http://spec.winprog.org/streams/
Was This Post Helpful? 0
  • +
  • -

#10 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: Is something missing in the way C++ stream I/O is taught?

Posted 04 September 2012 - 03:10 AM

Still, my advice is to write a tutorial. With your knowledge, I am sure that that tutorial would be just awesome.

And yeah, I was also one of those idiotic students one year ago.
Was This Post Helpful? 0
  • +
  • -

#11 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Is something missing in the way C++ stream I/O is taught?

Posted 05 September 2012 - 06:07 AM

View Postjimblumberg, on 03 September 2012 - 06:58 PM, said:

Quote

I'm quite disappointed with how C++ is taught.

Have you expressed your disappointment to the Dean of Students (or whatever his title is at your university), in writing?

Until the students, their parents, and the business community start to actively complain to the "powers" about the substandard education nothing will ever change.


Jim


I'm going to take the class first, not just read some materials presented online, the parts of book they use, and students accounts. I take it next semester and after I get a nice grade in it I will have a more respectable claim.
Was This Post Helpful? 0
  • +
  • -

#12 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 857
  • View blog
  • Posts: 2,343
  • Joined: 20-August 07

Re: Is something missing in the way C++ stream I/O is taught?

Posted 08 September 2012 - 04:43 PM

View Postaresh, on 04 September 2012 - 02:12 AM, said:

Hey Skidiver, how about writing a book/tutorial about C++ I/O stream, since you are unhappy with the existing ones? Many people will benefit from it :)

And I am serious, you should write one.

That book already exists - http://www.angelikal.../iostreams.html although it's not a beginner-level book, and the ins/outs of streams are (somewhat understandably) considered to be a bit of a niche subject by many. However it's still a good book to read if you are interested.

But as Skydiver pointed out, the problem is not with availability of books or information, its with the way the information is so poorly taught and understood among university teaching staff; not just for streams but C++ in general
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1