Solved

ostream with VC6 and VC7

Posted on 2004-10-26
935 Views
Last Modified: 2012-05-05
I've inherited the task of converting a C++ project from VC6 to VC.Net.  This is one of those horrors that was built 10 years ago with RogueWave so I can't possibly read all of the 50K+ lines of code.  My main problem seems to be with ostream.

Included in fcommon.h <-- I get about 7 different errors on this one line

ostream& operator<<(ostream& os, const string& rszString);

and in fcommon.cpp

ostream& operator<<(ostream& os, const string& rszString)
{
      return os << rszString.c_str();
}


Another example of a problematic chunk of code in matrix.h

  friend ostream& operator<< ( ostream& os,  const CMatrix<TYPE> &matrix ) {
      unsigned  i,j;
      
      for (i=0; i < matrix.nrows; i++ ) {
            for (j=0; j < matrix.ncols; j++ ) {
                  os << setprecision( 9 )<< matrix(i,j) << " ";
            }
            os << "\n";
      }
      return os;
  }

Also, more generally, is there any good documentation on differences between VC6 and .net?



0
Question by:garachen
    10 Comments
     
    LVL 19

    Expert Comment

    by:drichards
    What kind of errors are you getting because that code should compile fine?  The first bit certainly does, but I can't say for sure about the matrix bit.

    There are not too may real differences between VC6 and VC7 from code compile perspective.  The new compiler is more standard compliant and the C++ libraries have been updated.  The place you'll notice the most difference is MFC.  THere is stricter type checking on message handler function parameters, some things have been eliminated, and the implementation of CString has changed radically, but these are obvious when you hit them.  Most code will recompile just fine.  The code you show here SHOULD be in that category if you are rebuilding everything.  The RogueWave stuff should be recompiled as well (I assume it provides libararies?).
    0
     
    LVL 16

    Expert Comment

    by:nonubik
    There are some changes about streams, too. Like 'fstream.h' is now called 'fstream', 'ostream.h' it's 'ostream' and so on.
    I also had problems with some stream sources when porting from VC6 to VC7. Hope this helps. Otherwise, post the exact errors, please.
    0
     

    Author Comment

    by:garachen
    Errors for fcommon.h (on that single line)

    error C2143: syntax error : missing ';' before '&'
    error C2501: 'ostream' : missing storage-class or type specifiers
    error C2065: 'os' : undeclared identifier
    error C2059: syntax error : 'const'

    Errors for fcommon.cpp (two lines)

    (first line)
    error C2143: syntax error : missing ';' before '&'
    error C2501: 'ostream' : missing storage-class or type specifiers
    error C2086: 'int ostream' : redefinition inc\fcommon.h(43) : see declaration of 'ostream'
    error C3861: 'ostream': identifier not found, even with argument-dependent lookup
    error C3861: 'os': identifier not found, even with argument-dependent lookup
    error C2059: syntax error : 'const'

    (second line)
    error C2143: syntax error : missing ';' before '{'
    error C2447: '{' : missing function header (old-style formal list?)


    Errors in Matrix.h (first line only)

    error C2143: syntax error : missing ';' before '&'    inc\matrix.h(90) : see reference to class template instantiation 'CMatrix<TYPE>' being compiled
    error C2433: 'ostream' : 'friend' not permitted on data declarations
    error C2501: 'ostream' : missing storage-class or type specifiers
    error C2061: syntax error : identifier 'ostream'
    error C2501: 'CMatrix<TYPE>::operator`<<'' : missing storage-class or type specifiers
    error C2805: binary 'operator <<' has too few parameters
    error C2333: 'CMatrix<TYPE>::operator`<<'' : error in function declaration; skipping function body




    0
     
    LVL 16

    Expert Comment

    by:nonubik
    Try to add

    #include <ostream>

    in fcommon.h/.cpp
    0
     

    Author Comment

    by:garachen
    I gave it a try but no dice

    Here are the entire files.  Unfortunately, I just realized that the .cpp file is NOT called FCommon.cpp but has been pasted in to FObject.cpp

    I've never used RogueWave before so I don't know what it used to be doing with streams


    /*
       FCommon.h
    */

    #ifndef F_COMMON_H
    #define F_COMMON_H

    /*  created for pre-compiled headers  */

    #ifdef WIN32
        //  4018: 'expression' : signed/unsigned mismatch    
        //  4251: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
        //  4275: non – DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
        //  4291: 'declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception
        #pragma warning( disable : 4018 4251 4275 4291)
        #define DLL_EXPORT __declspec(dllexport)
    #else
        #define DLL_EXPORT
    #endif

    #define AIG_NO_EXPOSE_STD
    #include <UCommon.h>


    #include <FObject.h>
    #include <stdlib.h>
    #include <fstream>
    #include <math.h>
    #include <stddef.h>

    #include <iomanip>


    #include <ostream>

    #include <rw/cstring.h>
    #include <rw/tvsrtvec.h>
    #include <rw/tpsrtvec.h>
    #include <rw/tphdict.h>
    #include <rw/tpordvec.h>

    //  this can go when RW streams are replaced by STD streams
    //  - just stuffed definition in fobject.cpp for now


    ostream& operator<<(ostream& os, const string& rszString);

    //???  something about signed/unsigned char type ?
    //???  #pragma option -Jgx

    #include <vector.h>
    #include <matrix.h>

    //???  #pragma option -Jg

    #include <FError.h>

    #endif


    ///////////////////////////////////////////////////////////////////////////////////////////////////////



    /*
          FObject.cpp
    */

    /* include files */

    #include <FCommon.h>
    #include <FObject.h>
    #include <ostream>

    //  declared in FCommon.h
    //  this should have an FUtil.cpp/.h or something, but it's only until RWStreams disappear so
    //  it can go in here until then


    ostream& operator<<(ostream& os, const string& rszString)
    {
          return os << rszString.c_str();
    }

    //////////////////////////////////////////////////////
    /// CONSTRUCTOR & DESTRUCTOR
    //////////////////////////////////////////////////////

    FObject::FObject(void)
    {
    }

    //////////////////////////////////////////////////////

    FObject::~FObject(void)
    {
    }

    //////////////////////////////////////////////////////
    /// PRIVATE
    //////////////////////////////////////////////////////

    //////////////////////////////////////////////////////
    /// PUBLIC
    //////////////////////////////////////////////////////


    0
     
    LVL 19

    Assisted Solution

    by:drichards
    Looks like you need to add: 'using namespace std;' in your cpp files.

    And VC7 got rid of the legacy C++ headers (iostream.h, etc.) in favor of the newer  iostream, ostream, etc., so your code wouldn't even compile with the old names.  I think VS.NET (not 2003) still had the older headers.  I'm not sure.
    0
     

    Author Comment

    by:garachen
    The code complies with the .h extensions under VC6.  I've changed the ones that VC7 has forced me to so now it doesn't give me any errors such as "Cannot open include file ......" anymore.

    added 'using namespace std;' made no difference
    0
     
    LVL 16

    Accepted Solution

    by:
    'using namespace std;' should be added right below #include <ostream>
    0
     

    Author Comment

    by:garachen
    That does solve this particular problem but introduces a host of new ones.  Also included in this file is <FError> which conflicts somehow with 'using namespace std;' I ran into this same problem when I tried to include CString in this file.  I've tried moving <FError> above 'using namespace std;' to no avail.

    Why did this moving 'using namespace std;' below #include <ostream> work?  If I understood this I'd hope to be able to solve my other problems myself.

    Thanks alot.
    0
     
    LVL 19

    Assisted Solution

    by:drichards
    >> Why did this moving 'using namespace std;' below #include <ostream> work
    Beacuse the namespace did not exist until the ostream header was parsed.

    If 'using namespace std;' introduces problems for you, remove it and put the namespace in explicitly:

    --------------------------
    std::ostream& operator<<(std::ostream& os, const std::string& rszString);

    std::ostream& operator<<(std::ostream& os, const std::string& rszString)
    {
         return os << rszString.c_str();
    }

      friend std::ostream& operator<< ( std::ostream& os,  const CMatrix<TYPE> &matrix ) {
         unsigned  i,j;
         
         for (i=0; i < matrix.nrows; i++ ) {
              for (j=0; j < matrix.ncols; j++ ) {
                   os << std::setprecision( 9 )<< matrix(i,j) << " ";
              }
              os << "\n";
         }
         return os;
      }

    ----------------------------

    What kinds of errors do you get with FError?
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now