ostream with VC6 and VC7

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?



garachenAsked:
Who is Participating?
 
nonubikCommented:
'using namespace std;' should be added right below #include <ostream>
0
 
drichardsCommented:
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
 
nonubikCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
garachenAuthor Commented:
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
 
nonubikCommented:
Try to add

#include <ostream>

in fcommon.h/.cpp
0
 
garachenAuthor Commented:
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
 
drichardsCommented:
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
 
garachenAuthor Commented:
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
 
garachenAuthor Commented:
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
 
drichardsCommented:
>> 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.