Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ostream with VC6 and VC7

Posted on 2004-10-26
10
Medium Priority
?
970 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
Comment
Question by:garachen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 12418469
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
ID: 12419347
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
ID: 12421256
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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
LVL 16

Expert Comment

by:nonubik
ID: 12421390
Try to add

#include <ostream>

in fcommon.h/.cpp
0
 

Author Comment

by:garachen
ID: 12421697
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
drichards earned 600 total points
ID: 12422318
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
ID: 12422880
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:
nonubik earned 450 total points
ID: 12423049
'using namespace std;' should be added right below #include <ostream>
0
 

Author Comment

by:garachen
ID: 12427046
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
drichards earned 600 total points
ID: 12427672
>> 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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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