Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
RTL
C++
Codeguard
Date/Time
Exception Handling
Header Files
I/O
I/O Streams
Language Specifications
Locale/International API
Math
Math Emulator
Memory Management
Miscellaneous
MS Compat.
OS Interface
Overlays
Process Management
RTTI
Startup Code
STL
STLPort
Strings
Text Mode/Console API
Threads
Type Classification
Type Conversion
WIN API
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/RTL/C++/STLPort
[ Add a report in this area ]
Report #:
3470
Status:
Closed
basic_istream::operator>> returns an undefined value from an empty stream
Project:
C++Builder
Build #:
6.0.10.165
Version:
6.0
Submitted By:
Jussi Sirpoma
Report Type:
Minor failure / Design problem
Date Reported:
2/2/2003 7:47:48 PM
Severity:
Infrequently encountered problem
Last Updated:
2/8/2005 1:15:41 PM
Platform:
All versions
Internal Tracking #:
Resolution:
Won't Do
(Resolution Comments)
Resolved in Build:
:
None
Duplicate of:
None
Voting and Rating
Overall Rating:
No Ratings Yet
0.00 out of 5
Total Votes:
None
Description
The basic_istream::operator>>(int&) and basic_istream::operator>>(short&) return an undefined value if the stream is or goes to error state.
Other >> operators do not modify the value given as parameter.
From stl\_istream.h:
_Self& operator>> (int& __val) {
long __lval;
unsigned int __uval;
_M_get_num(*this, __lval);
__val = __lval;
__uval = __lval;
// check if we lose digits
// if ((__val != __lval) && ((unsigned int)__val != __lval))
if ((__val != __lval) && ((long)__uval != __lval))
this->setstate(ios_base::failbit);
return *this;
}
To make this operator behave the same way as the other >> operators do, the __lval could be initialized with __val.
This problem exist only when using STLPort.
Steps to Reproduce:
Run this program and check the value in tmp after reading it from the stream.
Expected: tmp has 0 in it
Actual Result: tmp has a random value
tmp2 has the expected 0.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <sstream>
#include <string>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
std::string str;
std::stringstream is;
int tmp = 0;
is >> tmp;
unsigned int tmp2 = 0;
is >> tmp2;
return 0;
}
//---------------------------------------------------------------------------
Workarounds
None
Attachment
None
Comments
None
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us