Subj : #include vs #include To : borland.public.cpp.borlandcpp From : I.candide Date : Mon Feb 21 2005 11:09 am Hello - Borland C++ 5.02 is doing something I do not understand. This is the code that came on the main cd as part of the ebook: How To C++. // File: filerea2.cpp // Example for C++ How-To // This program shows an effective way to read from a file using // arrays of char. // Copyright 1998, Jan Walter // NO WARRANTY. If this code breaks you get to keep both pieces. // Compiler verificiation: // Borland C++ 5.01A: Yes // DJGPP 2.01 w. GCC 2.81 : Yes // Watcom 10.5: Not Tried // Microsoft VC++ 4: Yes // Microsoft VC++ 5: Yes // Microsoft VC++ 6: Yes // GCC 2.7.2/Linux: Not tried // GCC/EGCS/Linux: Yes #include #include #include #ifdef __BORLANDC__ #pragma hdrstop #endif #include using namespace std ; int main( int argc , char** argv ) { if( argc != 2 ) { cout << endl << "Usage: fileread " << endl << "This program calculates the number of words, lines, and" << endl << "average word length in a file." << endl ; return 1 ; } int words = 0, lines = 0, totallen = 0 ; // allocate a large string out of freestore char* temp = new char[128] ; char tmpstring[45] ; // ios::nocreate is not part of the VC++ Implementation of STL // See the Visual C++ Users Guide Article Titled - Differences in iostream Implementation ifstream infile( argv[1], /*ios::nocreate | */ ios::in ) ; while( infile.getline( temp, 128 ) ) { strstream buffer ; int pwords = words ; lines ++ ; buffer << temp << ends ; while( buffer >> tmpstring && strlen( tmpstring )) { words ++ ; totallen += strlen( tmpstring ) ; } cout << (words - pwords) << ": " << temp << endl ; } delete[] temp ; double avglen = 0 ; if( words ) avglen = (double) totallen / (double) words ; cout << endl << "Statistics for file: " << argv[1] << endl << endl << "Number of lines: " << lines << endl << "Number of words: " << words << endl << "Avg. Word Length: " << avglen << endl ; return 0 ; } // end of file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ when I compile it as it stands I get the following error: Info :Building... Info :Compiling C:\CODE\filerea2.cpp Error: filerea2.cpp(28,22):Namespace name expected ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ when I ask for an explination, I get: Namespace name expected Compiler message The name of a namespace symbol was expected. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ So when I change line 7 of the code to read: #include and compile it I get: Info :Building... Info :Compiling C:\CODE\filerea2.cpp Warn : string.h(549,3):Functions containing for are not expanded inline Warn : string.h(557,3):Functions containing while are not expanded inline Warn : string.h(563,3):Functions containing for are not expanded inline Warn : string.h(575,3):Functions containing for are not expanded inline Warn : string.cc(686,32):Comparing signed and unsigned values Info :Linking C:\CODE\filerea2.exe ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ and the explanation: Functions containing reserved words are not expanded inline Compiler warning Also: Functions containing local destructors are not expanded inline in function 'function' (Command-line option to suppress warning: -w-inl) Reserved Words Functions containing any of these reserved words can't be expanded inline, even when specified as inline: break case continue do for goto switch while The function is still perfectly legal, but will be treated as an ordinary static (not global) function. A copy of the function will appear in each compilation unit where it is called. Local Destructors You've created an inline function for which the compiler turns off inlining. You can ignore this warning; the function will be generated out of line. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ How do I get the compiler to accept both instructions? Does not mean the same thing as: ? I know that I can suppress the message, but the explanation leads me to believe that the compiler will create extranious code when I include . I was taught that good programming does not include extranious code. Thank you for your help. Earl i.candide@verizon.net .