Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix istringstream read for readlines #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ahuston-0
Copy link

@ahuston-0 ahuston-0 commented Dec 15, 2021

When using operator>> on a istringstream, there is a chance that it will
silently fail if the contents of the buffer have all already been read.
This is not a major issue in most scenarios. However, in a situation like
this, the while loop will read all of the lines in, get to the last
line, and then (I believe, I'm not 100% sure on this) read the EOF but
still continue into the loop. As a result, using operator>> with 'line'
during the last iteration will fail and the contents of 'name', 'mass',
and 'radius' will stay the same. Essentially, without the if-statement
the last line will get printed twice. Since this code is used as an
example for the robosim individual assignment, this is important to fix
before it gets used again.

When using operator>> on a istringstream, there is a chance that it will
silently fail if the contents of the buffer have all already been read.
This is not a major issue in most scenarios. However, in a situation like
this, the while loop will read all of the lines in, get to the last
line, and then (I believe, I'm not 100% sure on this) read the EOF but
still continue into the loop. As a result, using operator>> with 'line'
during the last iteration will fail and the contents of 'name', 'mass',
and 'radius' will stay the same. Essentially, without the if-statement
the last line will get printed twice. Since this code is used as an
example for the robosim individual assignment, this is pertinent to fix
before it gets used again.

individual assignment
@ahuston-0
Copy link
Author

This may actually only be an issue with c-strings/char[]. I am looking at a version where a student used string for the variable line >> name instead of char name[20] and it actually produced the expected behavior. Not sure what the significance of this is, but its definitely interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant