|
-
Jun 4th, 2004, 12:54 AM
#1
Thread Starter
Hyperactive Member
Strange Compiler Anomaly: VC++/MinGW <resolved>
--EDIT--
The problem turned out to be some "bad implemenation" for in_avail() in GCC.
Here's the code in question:
Code:
string input;
cin >> input; //lets say the input is "hello hello"
cout << "Your Text: " << input << endl;
cout << "Number of chars: " << cin.rdbuf()->in_avail() << endl;
When I compile this with Mingw, in_avail() returns 0. However, when I compile it with VC++7, it returns a proper count of the number of characters left in the buffer (in this case, 7). Any idea why this happens?
Last edited by Comreak; Jun 4th, 2004 at 02:02 PM.
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
-
Jun 4th, 2004, 04:57 AM
#2
in_avail returns the number of elements in the input buffer, as far as I know there is no guarantee that when you press a key that character goes directly to cin's buffer.
Why do you want to use in_avail anyway?
-
Jun 4th, 2004, 05:36 AM
#3
Thread Starter
Hyperactive Member
Originally posted by twanvl
in_avail returns the number of elements in the input buffer, as far as I know there is no guarantee that when you press a key that character goes directly to cin's buffer.
Why do you want to use in_avail anyway?
If I wanted to clear the buffer, I'd use "cin.ignore(cin.rdbuf()->in_avail())".
I was just playing around and found out that something worked with one compiler and not with the other. Doesn't that strike you as a bit strange?
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
-
Jun 4th, 2004, 10:24 AM
#4
Fanatic Member
I was just playing around and found out that something worked with one compiler and not with the other. Doesn't that strike you as a bit strange?
No. Compilers are strange creatures that vary. If you are not using the standard, then there is no gaurantee that what compiles on one, compiles on another. (I believe) pragmas are different from compiler to compiler. Sometimes, even how you include things is different (MSVC++6 vs. Borland 5.02)
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
Jun 4th, 2004, 01:59 PM
#5
Thread Starter
Hyperactive Member
Well, I just checked the bug list over at http://gcc.gnu.org and apparently it wasn't a bug, just "poor implemenation". Hopefully, it'll get fixed in the next major release. Here's the report:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7744
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|