Solved

How do I display an integer into a label's text in visual c++?

Posted on 2008-06-22
2
484 Views
Last Modified: 2008-06-26
I am trying this:

int x = 5;
this->label1->Text = x;

but it displays error,

error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'int' to 'System::String ^'
        No user-defined-conversion operator available, or
        No standard conversion exists from the boxed form of the arithmetic type to the target type

thanks
0
Comment
Question by:Chrysaor
2 Comments
 
LVL 3

Expert Comment

by:sistemu
ID: 21841107
Hi,

it's a common error, you try to assign an integer to a text field.
You must convert from int to String.
I don't know exactly the sintax:

this->label1->Text = x.ToString();
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 21841473
you can use:
this->label1->Text = System::Convert::ToString(x);

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

708 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

12 Experts available now in Live!

Get 1:1 Help Now