You receive compiler errors when you compile a file that includes a C++ header file in a C program (104672)



The information in this article applies to:

  • Microsoft Visual C++ for Windows, 16-bit edition 1.0
  • Microsoft Visual C++ for Windows, 16-bit edition 1.5
  • Microsoft Visual C++ for Windows, 16-bit edition 1.51
  • Microsoft Visual C++ for Windows, 16-bit edition 1.52
  • Microsoft Visual C++, 32-bit Editions 1.0
  • Microsoft Visual C++, 32-bit Editions 2.0
  • Microsoft Visual C++, 32-bit Editions 2.1
  • Microsoft Visual C++, 32-bit Editions 4.0
  • Microsoft Visual C++, 32-bit Editions 6.0
  • Microsoft Visual C++, 32-bit Editions 5.0

This article was previously published under Q104672

SUMMARY

The following error is typically the first of many returned by the Microsoft C/C++ Compiler when attempting to compile a file that includes a C++ header file such as IOSTREAM.H in a C program:
ios.h(33) : error C2282: 'class' is followed by 'streambuf'. (missing ','?)
In more recent versions of the compiler, the system header files use #ifdef __cplusplus to prevent the contents from being parsed when compiled as "C" code.

There may also be multiple C2065, C2297, C2054, C2085, C2143, and C2144 errors, and eventually a C1003 error indicating that the error count reached 100.

MORE INFORMATION

The C/C++ compiler invokes either the C compiler or the C++ compiler according to the file's extension. If it ends in .C, the C compiler is invoked; if it ends in .CPP or .CXX, the C++ compiler is invoked.

To invoke the C++ compiler on a file that ends in .C or some other extension, use the /Tp switch to explicitly specify a C++ source file.

The sample code below produces the errors
error C2065: 'cout' : undeclared identifier
error C2297: '<<' : illegal, right operand has type 'char [12]'
if compiled with:
   cl hello.c
				
The code compiles fine if compiled with:
   cl hello.cpp
				

-or-

   cl /Tp hello.c
				

Sample Code

/* Compile options needed:  None
*/ 

#include <iostream.h>

void main (void)
{
     cout << "Hello World";
}
				

Modification Type:MinorLast Reviewed:4/24/2006
Keywords:kbProgramming kbhowto kbCompiler kbCPPonly kbinfo KB104672 kbAudDeveloper kbAudITPRO