Problem during compile (iostream.h error)

This is a discussion on Problem during compile (iostream.h error) within the C Programming forums, part of the General Programming Boards category; Hi, i working on a small project to learn again how to make some stuff in C. I use Borland ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Problem during compile (iostream.h error)

    Hi,

    i working on a small project to learn again how to make some stuff in C. I use Borland C++ 5.01. Ok at the moment i try to make a new dll file (the second one) and i want to put a nice search function (found on planet-source code) into this dll. I made already a dll and it seems that it works but now it seems that my Borland doesn´t like me or my code...here my source code of my second dll. I can not compile this source code with included iostream.h. If i include this iostream (i must do it, cause i need it for the search function) the Borland compiler gives me this error message:

    error: IOSTREAM.H(24,2):Error directive: Must use C++ for the type iostream.

    What should i change to compile this source code ?

    Code:
    [...header...]
    
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <iostream.h>
    #include <windows.h>
    
    /**********************************************
    Does a recursive search for an archived file
    starting at the root directory passed.......
    base conditions: out of directorys to call
    or found the file..........................
    **********************************************/
    __declspec(dllexport) void findPath(char *root, char *file, char *buffer)
    {
    	//stuff for the file searc loop
    	HANDLE          h;
    	BOOL            ok;
    	WIN32_FIND_DATA	fd;
    
    	char start[256];//character var's...
    	char dir[256];
    	bool found=false;//search flag
    
    	char test[1000];//paranoia
    	strcpy(test,buffer);//using test as a temp location
    	int tlen = strlen(file);//get length of file name
    	if(testStrings(test,file))//test for it
    	{
    		return;//return if it is there...no need to look further
    	}
    
    	if(strlen(root)>0)//if they passed a valid string for the root
    	{
    		strcpy(start, root);//modify it to search for all files/folders....
    		strcat(start,"\\*");
    	}
    
    	//steven at http://world.std.com/~swmcd/steven/ms/bugs.html#right gets credit for the for loop idea..processing inside the loop is mine
    	for (h =FindFirstFile(start, &fd), ok=1;h!=INVALID_HANDLE_VALUE && ok; ok=FindNextFile(h, &fd))
    	{
    		if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)//use bitwise and to test the returned fileattributes
    		{
    			strcpy(dir,fd.cFileName);//assuming it is a dir so copy over
    			if((testStrings(dir,".")==false))//make sure it is not the defaul parent...
    			{
    				if((testStrings(dir,"..")==false))//..or child indicator, copying this over results in infinite recursion
    				{
    					if(found == false)//if we have not found the file in this current call then make a call
    					{
    						strcpy(test,root);
    						strcat(test,"\\");
    						strcat(test,dir);
    						findPath(test,file,buffer);//and recurse through them.....
    					}//end found
    				}//end .. test
    			}//end . test
    		}//end dir test
    		if(fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)//now use bitwise and to check for file flag
    		{
    			found = testStrings(file,fd.cFileName);//if we have a file is it the one we want?
    			if(found == true)
    			{
    				strcpy(buffer,root);//if it is create the full path name to it and copy into buffer
    				strcat(buffer,"\\");
    				strcat(buffer,fd.cFileName);
    			}//end found test
    		}//end archive test
    	}//end for
    
    	int error = GetLastError();
    	if (error!=ERROR_NO_MORE_FILES)
    	    printf("Find*File: error %d\n", error);
    
    	if (h!=INVALID_HANDLE_VALUE)
    	{
    	    BOOL ok = FindClose(h);
    		if (!ok)
    	        printf("FindClose: error %d", GetLastError());
    	}
    }
    
    
    
    //test's to charS for equality, returns true or false
    /*static bool */
    testStrings(char *s1, char *s2)
    {
     	int x1=0;
    	bool ret=true;
    	x1 = strlen(s1);
    	if(strlen(s2) != (unsigned)x1)
    	{
    		ret=false;
    	}
    	else
    	{
    		for(int i=0;i<x1;i++)
    		{
    
    			if(s1[i] != s2[i])
    				ret = false;
    		}
    	}
    	return ret;
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Make up you mind, is this C or C++ code? If it is C++, then we are in the age of compliance:

    <iostream>
    <cstdio>
    <cstring>

    You are probably trying to use C++ on a C compiler, that is a no no.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    If your source file has a ".C" extension, then the compiler will compile that file based on C rules. You need to change it so the extension of the source code file is ".cpp" or whatever your compiler will recognise as being a C++ source file. Then your compiler will know to compile the file according to the C++ rules.
    I used to be an adventurer like you... then I took an arrow to the knee.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    *boing*..just renamed into *.cpp and bingo..no error ..thanks very much

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    You should probably write valid C++ code wgile you are at it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21