Solved

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

Posted on 2008-06-22
2
489 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

777 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