jtran007
asked on
Compiling Error VS2010
Hi,
I am the beginner of Visual C++(2010), I got the compiling errors
from this attached code.
Please give me advice.
Thanks,
JT
I am the beginner of Visual C++(2010), I got the compiling errors
from this attached code.
Please give me advice.
Thanks,
JT
#include "stdafx.h"
#include <iostream>
using namespace std;
class A
{
public:
int x,y,z;
A(int a, int b, int c) { x=a; y=b; z=c;}
}
ostream &operator<<(ostream &stream, A o)
{
stream << o.x << ",";
stream << o.y << ",";
stream << o.z << endl;
}
using namespace System;
int main(array<System::String ^> ^args)
{
//Console::WriteLine(L"Hello World");
A a(1,2,3), b(2,3,4), c(5,6,7);
cout << a << b << c;
return 0;
}
Could you list the errors with the line numbers?
I'm not sure what System namespace is. AFIK for your includes, line 4 should be good.
The C++ part has a few problems nin terms of syntax and declaration of such an operator, the following works fine:
#include <iostream>
using namespace std;
class A;
ostream& operator<<(ostream &stream, A& o);
class A
{
friend ostream& operator<<(ostream &stream, A& o);
public:
int x,y,z;
A(int a, int b, int c) { x=a; y=b; z=c;}
};
ostream& operator<<(ostream &stream, A& o)
{
stream << o.x << ",";
stream << o.y << ",";
stream << o.z << endl;
}
int main()
{
A a(1,2,3), b(2,3,4), c(5,6,7);
cout << a << b << c;
return 0;
}
Ooops, sorry, little correction:
#include <iostream>
using namespace std;
class A;
ostream& operator<<(ostream &stream, A& o);
class A
{
friend ostream& operator<<(ostream &stream, A& o);
public:
int x,y,z;
A(int a, int b, int c) { x=a; y=b; z=c;}
};
ostream& operator<<(ostream &stream, A& o)
{
stream << o.x << ",";
stream << o.y << ",";
stream << o.z << endl;
return stream;
}
int main()
{
A a(1,2,3), b(2,3,4), c(5,6,7);
cout << a << b << c;
return 0;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Thanks jkr. You are ringt; however, I'd like this code running under VS2010 for c++ since
once I chose the console project, the Visual studio automatically adds "using namespace System"
and int main(array<System::String ^> ^args).
How is this code modified to work in this vs2010 environment but still keeps the same function call?
Thanks again,
JT
Thanks jkr. You are ringt; however, I'd like this code running under VS2010 for c++ since
once I chose the console project, the Visual studio automatically adds "using namespace System"
and int main(array<System::String ^> ^args).
How is this code modified to work in this vs2010 environment but still keeps the same function call?
Thanks again,
JT
You mean the following?
int main(int argc, char** argv)
{
A a(1,2,3), b(2,3,4), c(5,6,7);
cout << a << b << c;
return 0;
}
ASKER
Hi jkr,
I mean this call which is autmatically added by VS2010 when the console app is chosen:
int main(array<System::String ^> ^args)
Do you have any idea since it is totally different from the one (int main(int argc, char** argv)
that I usually use in VS6.0.
Thanks,'
JT
I mean this call which is autmatically added by VS2010 when the console app is chosen:
int main(array<System::String ^> ^args)
Do you have any idea since it is totally different from the one (int main(int argc, char** argv)
that I usually use in VS6.0.
Thanks,'
JT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
JT
JT