--- connect4v1.1/bd_string.cpp 2002-09-27 19:20:25.000000000 -0700 +++ connect4v1.1/bd_string.cpp 2002-09-27 19:20:53.000000000 -0700 @@ -4,6 +4,37 @@ #include #include "bd_string.h" +// myGetline: +// The gcc 3.1 version of the 'getline' function has a bug - it requires +// two delimiters (e.g. newlines) before it accepts the input +// See gcc problem report # 6648 +// The 'myGetline' function provides a replacement for 'getline' +// Sample use: char name[100]; myGetline(cin, name, 100); + +std::istream& myGetline(std::istream& in, char* buffer, std::streamsize n, char delim = +'\n') +{ + if (in.peek() == delim) + { + // the gcc 3.1 version of the 'get' function fails if there + // are no characters before the delimiter (e.g. an empty line). + // This would seem to be a bug but the discussion on gcc problem + // report # 4419 says that this behaviour accords with the standard. + + buffer[0] = '\0'; + } + else + { + in.get(buffer, n, delim); + } + + if (in.good() && strlen(buffer) < n - 1) + { + // eat the delimiter + in.ignore(1); + } + return in; +} String::String() { @@ -410,7 +441,7 @@ temp=new char[maxChar]; - inputStream.getline(temp, maxChar); + myGetline(inputStream, temp, maxChar); *this=temp; delete [] temp;