ja************@gmail.com wrote:
Can somebody please tell me why:
#include <iostream>
int main(int argc, char *argv[]) {
int ia;
ia = 23432234;
std::cout << ia.ToString() << '\n';
}
always produces an output of 1? Actually, I should rephrase that...
When compiling Visual C++ .NET 2003 warns that "warning C4800:
'System::String __gc *' : forcing value to bool 'true' or 'false'
(performance warning)" So, I understand that is why it always
produces a 1.
What I dont understand is why it has to be a bool. I thought the point
of ToString was to convert the int to a char*. What am I missing? If
this is not the correct way to do this can someone point me in the
right direction?
Please be gentle as I am VERY new to c++.
Although I also program in .NET I am about to get a headache too. :-)
At first ia.ToString() is a .NET specific feature and is not part of ISO
C++.
What you should do is learn some ISO C++ first and then move on to .NET
Check a page of mine:
http://www23.brinkster.com/noicys/learningcpp.htm
Now in your case, int maps to the .NET type Int32.
Int32::ToString() returns a String * pointer.
cout has not any operator overload for a String *. And that's why it
outputs non-sense.
But you have got yourself in quite a mess. Learn first some ISO C++,
that is the language itself, and then .NET.
Your subject is off topic here, since the topic of this group is ISO C++.
You should ask in microsoft.public.dotnet.languages.vc newsgroup.
If it doesn't appear in your news server use the public MS news server:
msnews.microsoft.com
To be technically accurate, your code corrected:
#using <mscorlib.dll>
int main()
{
using namespace System;
int ia;
ia = 23432234;
// Or Console::WriteLine(ia.ToString());
// but prefer the one below:
Console::WriteLine("{0}", ia.ToString());
}
--
Ioannis Vranos
http://www23.brinkster.com/noicys