Date: Mon, 13 Dec 1993 16:42:48 +22311259 () From: Ron Grunwald Subject: Problem programming C++ streams with 32-bit GCC compiler To: djgpp AT sun DOT soe DOT clarkson DOT edu Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Dear G++ for MSDOS programmers, I have recently acquired the GNU G++ 32-bit compiler for MSDOS systems. The package is called DJGPP which I downloaded from an anonymous FTP site. This compiler is apparently also capable of compiling C++ source code. However, this weekend I came across a problem involving C++ streams. The aim was to read string fields from an ASCII text file. This can be accomplished using the GET or GETLINE member functions of the class istream. When I compiled the code with GCC it gave no error or warning messages and generated the executable. However, when I ran the program and displayed the string which was meant to contain the string field from the input file, nothing came up! The same C++ code compiled under Borland C++ Version 3.1, works fine however. My question is: Is there anyone who can give me advice on how to get around this problem? Is this a bug in the GCC compiler package? I really do want to use GCC for my future program developments rather than the Borland compiler and tools. Below is the sample code that exposes this problem with the DJGPP G++ compiler. ---------------------------------------------------------------------- #define GCC_32BIT_COMPILE #include #include #ifdef GCC_32BIT_COMPILE #include #else #include #endif #define MAX_STRING_LENG 100 #define SPACE_CH ' ' main(int argc, char **argv) { char string_field[MAX_STRING_LENG]; ifstream Read_operator; if(argc != 2) { cout << "Program Usage: CC_FREAD \n"; exit(-1); } Read_operator.open(*(argv + 1), ios::nocreate); if(! Read_operator) { cout << "Error: Unable to locate file " << *(argv + 1) << endl; exit(-1); } // Read the first character string, terminated by a space, from an input // file and display it. // Read_operator.getline(string_field, MAX_STRING_LENG, SPACE_CH); cout << "First string field contains: " << string_field << endl; Read_operator.close(); } ----------------------------------------------------------------------- Thanks for any comments or suggestions made that may help me. Regards, Ronald. +---------------------------------------------------------------------+ | Author : Ronald Grunwald | | Internet : rgrunwal AT bluering DOT cowan DOT edu DOT au | | Department : Information Technology | | Division/Faculty : Operations and Systems Management | | Institution : Edith Cowan University, Churchlands Campus | | Location : Perth, Western Australia | +---------------------------------------------------------------------+