Re: VS2005 C++ Express basic_istream::get(buf, size, delim) bug
{ Note: this article is cross-posted to [comp.lang.c++.moderated] and
[microsoft.public.vc.language]. For follow-ups, please keep in mind
that "environment specific" is a standard clc++m rejection reason.
I.e., please keep the discussion on-topic, concerning the C++ language
and how C++ compilers implement the language. -mod }
"Terry G" wrote:.
Is this a compiler bug? Does your C++ compiler produce the same results?
#include <iostream>
#include <limits>
int main() {
static char Line[1024];
while (std::cin.get(Line, sizeof(Line), '\n')) {
std::cin.ignore(std::numeric_limits<int>::max(), '\n');
std::cout << ':' << Line << std::endl;
}
} // main
It seems that cin.get(char*, size_t, '\n') "fails" on a blank line.
g++ has the same behavior if I strip the carriage returns from the line
ends.
I would have expected it to succeed with gcount() == 0.
I can't believe I haven't encountered this before. VS2003 C++ 7.1
behaves the same.
I guess I've been using getline(cin, str) and unknowingly avoided this.
How do I fix this code, then, without using std::string?
terry
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]