diff -ruNp connect4v1.2-orig/bd_string.cpp connect4v1.2/bd_string.cpp --- connect4v1.2-orig/bd_string.cpp 2001-11-09 20:26:41.000000000 -0600 +++ connect4v1.2/bd_string.cpp 2014-08-12 19:51:14.000000000 -0500 @@ -1,9 +1,40 @@ -#include +#include #include #include #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 @@ const String &String::getLine(istream &i temp=new char[maxChar]; - inputStream.getline(temp, maxChar); + myGetline(inputStream, temp, maxChar); *this=temp; delete [] temp; diff -ruNp connect4v1.2-orig/bd_string.h connect4v1.2/bd_string.h --- connect4v1.2-orig/bd_string.h 2001-09-11 21:53:40.000000000 -0500 +++ connect4v1.2/bd_string.h 2014-08-12 19:53:38.000000000 -0500 @@ -1,7 +1,9 @@ +using namespace std; + #ifndef BD_STRING #define BD_STRING -#include +#include class String { diff -ruNp connect4v1.2-orig/board.cpp connect4v1.2/board.cpp --- connect4v1.2-orig/board.cpp 2001-06-23 00:14:50.000000000 -0500 +++ connect4v1.2/board.cpp 2014-08-12 19:54:08.000000000 -0500 @@ -1,4 +1,6 @@ -#include +using namespace std; + +#include #include #include "break.h" diff -ruNp connect4v1.2-orig/heuristic.cpp connect4v1.2/heuristic.cpp --- connect4v1.2-orig/heuristic.cpp 2002-09-28 22:06:34.000000000 -0500 +++ connect4v1.2/heuristic.cpp 2014-08-12 19:51:14.000000000 -0500 @@ -1,5 +1,5 @@ #include -#include +#include #include #include "debug.h" diff -ruNp connect4v1.2-orig/main.cpp connect4v1.2/main.cpp --- connect4v1.2-orig/main.cpp 2002-09-28 22:10:50.000000000 -0500 +++ connect4v1.2/main.cpp 2014-08-12 19:51:14.000000000 -0500 @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include "debug.h"