Solved

C++  vs Visual C++ .NEt

Posted on 2002-06-24
16
182 Views
Last Modified: 2013-12-14
I built a C++ console application program using Borland C++ 5.

I recently purchased Visual Studio C++.NET and wanted to make a few changed to this application. IT's a compare program, nothing complex, so i created a new project and copied the main.cpp file contents into the new Visual C++.Net file.

I built the program but it does not compile. It had many errors. but all the errors were....
----------

binary 'operator' : 'type' does not define this

--------

what the lines consist of are

outfile<<name<<" "<<name2<<endl;

it can not read the << for some reason.

I'm not sure why this is, if there is something in the Visual C++.NEt environment that prevents me from compiling or what not.

Because this program works and runs and I use when i compiled and built it with Borland C++ 5.

Thanks for your time,
Pete "
0
Comment
Question by:pjam062402
  • 6
  • 4
  • 3
  • +3
16 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 7104954
What is "outfile"?  My guess is that it's a Borland-ism or you're left out an important #include.

Show MORE code.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7104958
Please post more of your code.

What type is outfile?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7104962
You beat me to it jhance.....

pjam,
Also, what type is name and name2?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 32

Expert Comment

by:jhance
ID: 7104963
I guess great minds think alike....  Or is that simple minds....  No matter.  ;-)
0
 

Author Comment

by:pjam062402
ID: 7105043
oh sorry, didn't want to post too much code to clobber people with info,


outfile is just derived from

ifstream(infile1);
ifstream(infile2);
ofstream(outfile1);
ofstream(outfile2);

i tried it  

ofstream outfile1;

and

ofstream(outfile1);

same results.

and NAME is just a variable that i wanted to post to the outfile.

but i keep getting

Compiler Error C2679       and C2678


It always compiled and ran with Borland C++, in fact I currently use the program, but i just wanted to make a few changes to the program and recently purchased the Visual C++.Net and will be using this software from now on.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7105343
Do you have:

#include <fstream.h>

In your file?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7105375
ofstream(outfile1);//Will not work

It should be "ofstream outfile1".

You should be using #include <fstream> and if you don't have using namespace std, you need to prefix std:: to your STL types.
Example:
#include <fstream>
std::ofstream outfile1;

If you're using fstream.h, then this could be your problem, because this file header is not part of the standard, and therefore, it can be different from one compiler to the next.
0
 

Author Comment

by:pjam062402
ID: 7106520
I included <fstream>  and changed it to <fstream.h>

I used std::fstream outfile1       and

fstream outfile 1.


this is the new error I get  for and so on

std::ifstream infile1;


Compiler Error C2079
'identifier' uses undefined class/struct/union 'name'

The specified identifier is an undefined class, structure, or union.

Possible cause

Initializing an anonymous union.
0
 

Author Comment

by:pjam062402
ID: 7106530
I included <fstream>  and changed it to <fstream.h>

I used std::fstream outfile1       and

fstream outfile 1.


this is the new error I get  for and so on

std::ifstream infile1;


Compiler Error C2079
'identifier' uses undefined class/struct/union 'name'

The specified identifier is an undefined class, structure, or union.

Possible cause

Initializing an anonymous union.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7107046
It not clear to me what you are doing or even trying to do.

How about:

#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
     ofstream outfile1;
     ifstream infile1;

     return 0;
}
0
 

Author Comment

by:pjam062402
ID: 7107833
int _tmain(int argc, _TCHAR* argv[])

if i'm not mistaken this is managed C++,  I'm not building a managed C++ application.  



I am just trying to get my program to work.   I won't post the code here because it's over 1000 lines of code.   It's basically a program that compares two files.  One old and one new.  BUt there are many files to be compared and according to what menu choice you pick, you will compare the two files you need compared.

However the problem is in regards to that this application compiled and was built using Borland C++ 5.0.  It ran successful and I currently use the application.

I just wanted to make a few changes to the code, but  I no longer use Borland C++ 5.0   I use Visual C++.NET and i built the program and i recieved these errors. Which I did no before using borland C++ 5.0


the error I received this time

Compiler Error C2079
'identifier' uses undefined class/struct/union 'name'

The specified identifier is an undefined class, structure, or union.

Possible cause

Initializing an anonymous union.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7107895
You're mistaken, this is a standard C++ console application in Visual Studio .NET.

I tried to show you an example of what is needed to get an ifstream and an ofstream.

I don't want to see your 1000 lines of code as your error is simple.  But what you've posted here is inconsistent.

You mix "metaphors" for no obvious reason:

std::fstream outfile1
fstream outfile 1


You are typing syntax errors:

fstream outfile 1.


So this makes it VERY VERY unclear what you are doing and what is wrong.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7107912
Here, I fixed the example so that you aren't confused:

#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
     ofstream outfile1;
     ifstream infile1;

     return 0;
}

PLEASE TRY TO COMPILE ONLY THIS CODE.  I'm TELLING YOU THIS WORKS:

---------------------- Done ----------------------

    Build: 1 succeeded, 0 failed, 0 skipped
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7109382
You are misspelling the name of your variable.  It is not
    name
it is something else.  Perhaps
    NAME
or maybe
    Name
or even
     nAmE

But I don't know for sure.  I called the psychic hotline and even they waffled around a bit.  And they charged me $17.34 even though the first two minutes were free.  I was able to chat with Elvis for a while, so you don't owe me anything.

-- Dan
0
 
LVL 11

Expert Comment

by:griessh
ID: 7262505
Dear pjam

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jhance"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7419714
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

773 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