Solved

C++  vs Visual C++ .NEt

Posted on 2002-06-24
16
179 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

759 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

18 Experts available now in Live!

Get 1:1 Help Now