none
Problem In Shifting my code from Borland C to Visual C++ 6 RRS feed

  • Question

  • Hi guys I am doing pretty ancient work on a side project so i hope this doesn't tick you people of :)
    I decided to shift my entire code form BC++ to Visual C++ 6.0 and , after solving hundreds of little errors I finally endded up with this error

           #include <fstream>   //I included both libraries
           #include <fstream.h>
       fstream file_test(NewFilePath,ios::in); -----------> this line gets highlighted with the error
                              if (file_test)
                              {
                              ........
                              .......
                              }
                             else
                              {
                              cout << "File Does Not Exist\n";
                              }

    //Error shows up:
    Error c2451 : conditional expression of type 'class fstream' is illegal

    Also If i insert  using namespace std;

    then i get the error c2872: 'fstream' ambigious symbol ?? why is that??

    should i use namespace or not??

    and one more question:
    even though i declared               

    #include <string>
    #include <string.h>
    yet i still get errors on using the variable string until i use

    using std::string ;
    why do we need to declare the above statement in visual C++ 6.0 whereas in BC++ there was no need??

    A candle loses nothing by lighting another candle.
    Sunday, October 11, 2009 8:09 AM

Answers

  • Hang on. Since that function is not available in VC++, how did you manage to get a
    clean compile? If it compiles without errors then you must have supplied a header
    with the prototype or the prototype itself. What did you do? You arern't mixing
    headers from Borland and VC++ are you?

    - Wayne
    • Marked as answer by Nancy Shao Monday, October 19, 2009 2:22 AM
    Monday, October 12, 2009 7:10 PM

All replies

  • Get rid of the fstream include with the .h extension.

    The fstream class is in the std namespace. So use:

    #include <fstream>

    using namespace std;

    or

    using std::fstream;

    or

    std::fstream file_test(NewFilePath,ios::in);


    Quote>why do we need to declare the above statement in visual C++ 6.0
    Quote>whereas in BC++ there was no need?

    You're comparing apples and oranges. The STL/SCL string class is in the std namespace in
    VC++, but may not have been in whatever version of BC++ you were using. You can't compare
    the requirements of compilers of different vintage - the language Standard evolved over
    time and so did compilers. If you use a newer Borland/Embarcadero compiler it will also
    require the std namespace.

    - Wayne

    Sunday, October 11, 2009 5:02 PM
  • did just that and i am still getting the error
           error C2451: conditional expression of type 'class std::basic_fstream<char,struct std::char_traits<char> >' is illegal
            Ambiguous user-defined-conversion

    on the following line
               fstream file_test(NewFilePath,ios::in);
               if (file_test)  --->this line gets highlighted
               {
                }
    i also tried
             fstream file_test(NewFilePath,ios_base::in);
    A candle loses nothing by lighting another candle.
    Monday, October 12, 2009 2:01 PM
  • Solved that error by using
    if (!!file_test)  --->this line gets highlighted
               {
                  }

    now no errors during compilation but when i link it i get the error
    Main.obj : error LNK2001: unresolved external symbol _closedir


    A candle loses nothing by lighting another candle.
    Monday, October 12, 2009 3:02 PM
  • _closedir , opendir ... These functions are not available in Visual C++ .
    thank for the help though.



    A candle loses nothing by lighting another candle.
    Monday, October 12, 2009 3:09 PM
  • Hang on. Since that function is not available in VC++, how did you manage to get a
    clean compile? If it compiles without errors then you must have supplied a header
    with the prototype or the prototype itself. What did you do? You arern't mixing
    headers from Borland and VC++ are you?

    - Wayne
    • Marked as answer by Nancy Shao Monday, October 19, 2009 2:22 AM
    Monday, October 12, 2009 7:10 PM
  • Ok looks like you caught me.. :) I copied the header from the BC compiler and pasted it in the VC compiler (I know pretty stupid...) thats how i gues it compiles but does not run... (Plz forgive my ignorance :))

    A candle loses nothing by lighting another candle.
    Tuesday, October 13, 2009 5:07 AM