473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ToString behavior

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++.

Thanks,
Jason

Jul 23 '05 #1
3 1629
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';
I don't know what this is, but it's not C++ (and it wouldn't compile in
C++ as `ia', being an int, is not an aggregate, hence there's nothing to
`dot' from.

If it's a .net thing, an MS newsgroup would be an appropriate place to ask.
}

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++.

I was. ;-)

HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #2
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
Jul 23 '05 #3
Thanks for your help. WriteLine is what I was looking for.

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: RonG | last post by:
This might seem like a stupid question but I'd really appreciate an answer TextBox.Text is property yet it has a ToString() method. In other words, i can type in textBox1.Text.ToString() and it...
1
by: Ed S | last post by:
I'm trying to format a double with this behavior: 1) should only show 8 characters (character count before and after decimal added together). 2) if greater than 7 characters to the left of the...
3
by: Nathan R. | last post by:
Hi, I'm seeing something that seems extremely strange to me. All I'm doing is overriding the toString method in one of my classes, so that instances will display the way I'd like in Combo boxes...
101
by: Sean | last post by:
Book I am reading says that Cstr() is best method for efficency and safety however it doesnt compare that method of the .ToString() method. Which is best. Thanks
5
by: Don | last post by:
I have a project wherein I derive a combobox and create a custom Populate() method for it to fill it with objects of a custom class I also created in a second project that the combobox project...
25
by: John A Grandy | last post by:
In .NET v1.1.4322 , in a VS.NET application , has anyone ever run into the bizarre situation where at runtime .NET believes that the ToString() method does not exist ... Sometimes this problem...
1
by: Tom | last post by:
I need to modify the default behavior of Date.ToString() on all pages of my ASP.Net (2.0) site. I don't need to localize my app (it's an intranet-only site), but I need to enforce a specific...
6
by: Zeng | last post by:
Math.Round has good behavior as following: Math.Round(3.45, 1); //Returns 3.4. The last '5' is thrown away because 4 is even Math.Round(3.75, 1); //Returns 3.8. The last '5' is used because '7'...
3
by: Mike S | last post by:
Maybe I'm missing some fundamental unwritten law of OOP, but I was wondering why the VB.NET compiler doesn't take advantage of the fact that all .NET objects, being derived from the Object base...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.