[Convert problem] Visual C++ --> codeblocks.

Good day all,

I've created a project in Visual C++ for school (posted an topic about that, but can't find it right now) BUT the assignment was to create it in codeblocks... I just don't like that program in comparrison with visual C++ 2010. So the I tried to convert my first assignment (C-assignment) to codeblocks and that worked perfect! (only needed to delete 1 #include) so I thought lets try again.. yeah fail.. So my question is:
Which of the following #includes is not ASCII (if I say it right, without all windows features).

1
2
3
4
5
#include <iostream>         
#include <string>           
#include <fstream>         
#include <stdio.h>
#include <stdlib.h>           // C - include. 



The errors:
1
2
3
4
5
6
C:\Users\...\Opdracht2 - Codeblocks\Opdracht2\Main.cpp||In member function 'std::string ReadFile::OpenBestand(int, char**)':|
C:\Users\...\Opdracht2 - Codeblocks\Opdracht2\Main.cpp|62|error: 'strcmp' was not declared in this scope|
C:\Users\...\Opdracht2 - Codeblocks\Opdracht2\Main.cpp||In member function 'int ReadFile::UitlezenBestand(int, char**)':|
C:\Users\...\Opdracht2 - Codeblocks\Opdracht2\Main.cpp|82|error: variable 'std::ifstream inFile' has initializer but incomplete type|
||=== Build finished: 2 errors, 0 warnings ===|


Thanks for any comments, help or tips!

Greets,
Leek.
Last edited on
Your headers are all fine.

The problem with your first error is you are not including all the headers you need to be. Specifically, you're using strcmp without including the necessary header (#include <cstring> )

As for the second error...

C:\Users\...\Opdracht2 - Codeblocks\Opdracht2\Main.cpp|82|error: variable 'std::ifstream inFile' has initializer but incomplete type|

That hints that you aren't #including <fstream>, but from your post you are! So I don't know what the problem is here.

Can you post the code that's giving this error?
at this code it goes wrong:

1
2
3
4
5
6
7
8
9
/***********************************************************************/
string ReadFile::OpenBestand(int argc, char *argv[]){  
/***********************************************************************/
	for (iargcount = 1; iargcount < argc; iargcount++){                 
		if (strcmp(argv[iargcount], "-i")){					    
			sBestandsLocatie = argv[iargcount + 1];	
                  }
	}
	return sBestandsLocatie;                                            } // Einde OpendBestand. 


the complete file where the class is declared is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <string>
#include <iostream>
using namespace std;

class ReadFile
{
private:
// Init's.
        int Uitlezen, 
             ivergelijk,							
             iinhoudCnt,				
             iargcount;                                                  
        string sBestandsLocatie, sTemp;                                 
        char cText;
        class Gev *huidige, *eerste, *laatste;                          
public:
    ReadFile(){
        Uitlezen    = 0;
        ivergelijk  = 1;								    
        iinhoudCnt  = 0;						           
        iargcount   = 0;
        sBestandsLocatie.clear();                                                                                                
        sTemp.clear();
    }
   int UitlezenBestand(int argc, char *argv[]);
   string OpenBestand(int argc, char *argv[]);
}; // einde class Readfile 


In here there is no #include<fstream>
But when I remove the other #includes this won't give an error in visual C++.
So I think this line of code is redundant?

The ifstream error comes from:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int ReadFile::UitlezenBestand(int argc, char *argv[]){
/***********************************************************************/
	ifstream inFile (sBestandsLocatie);		           	                
    huidige = NULL;
    eerste  = NULL;
    laatste = NULL;

    linkedlist Plink;

    if(!(inFile.is_open ())){
        cout << "Bestand niet geopend." << endl;
        return 0;
    }...
...
...
Last edited on

So I think this line of code is redundant?


No that just means that either the <string> or the <iostream> (probably the latter) include fstream in VC++. That is in no way guaranteed behavior though, so even in VC++ you should add the include fstream line.

PS: Standard C headers shouldn't be accessed with <something.h> but with <csomething> in C++.
@hanst99
Even in VC++ I include the fstream line.
I think that one of my #includes is specialy used for VC++ and I need an other one for normal ACII compiling.

my includes:
1
2
3
4
5
6
7
#include <iostream>         
#include <string>           
#include <string.h>
#include <cstring>
#include <fstream>          
#include <stdio.h>
#include <stdlib.h> 


When I enter the line: #include <fstream>
The number of total errors increases, saying:

C:\Users\...\Main.cpp||In member function 'int ReadFile::UitlezenBestand(int, char**)':|
C:\Users\...\Main.cpp|84|error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\fstream|454|note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\fstream|440|note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|81|note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)|
||=== Build finished: 1 errors, 0 warnings ===|

when I comment the #include <fstream> I get this error:

C:\Users\...\Main.cpp||In member function 'int ReadFile::UitlezenBestand(int, char**)':|
C:\Users\...\Main.cpp|84|error: variable 'std::ifstream inFile' has initializer but incomplete type|
||=== Build finished: 1 errors, 0 warnings ===|


Any idea? somebody?
Last edited on


C:\Users\...\Main.cpp||In member function 'int ReadFile::UitlezenBestand(int, char**)':|
C:\Users\...\Main.cpp|84|error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)'|


This means you can't create an ifstream from a string - you have to convert it to a C string with the c_str() method first. I know, incredibly lame, but that's how it is.

You need to learn to read these error messages - I know they can appear quite cryptic at first, but after a while you get used to it. Just like after a while you can easily see that (x^2-1)/(x-1) = x+1 , x=/=1, but it takes a bit of practice to do so.
ahhh...
Thanks I'll try it out and give u a reply if it worked.

Greets,
Leek.
PS: don't include headers like <stdio.h> - if you really need those C headers include them with <cstdio>.
@hanst99

working smooth!
briljant! thank you very much.

I even removed 4 headers from the main.cpp and it still keeps on going:
1
2
3
4
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stdio.h> 


Thanks.
Topic archived. No new replies allowed.