Replies To: How to conversion array to one string...

Re: How to conversion array to one string...

Help me,
I have problem about method to convert array (type int) to one string (type char),
e.g. input as :
array[1]=1
array[2]=2
array[3]=3
array[4]=4
.
.
.
array[n]=n
stuff of every array are independent.

If i want in the output denote an one string as below :
I am defined variabel name of string is *string than the product is string="1234.....n".

How to implementation solve the problem in the C++ Program.

Thanks.
ImamkomC++

hi

Conversion falls into two categories:

Implicit

Explicit

Implicit occurs when the compiler will allow the conversion and does so at compile time. An integer and a char can be converted implicitly by this code:

int a = 5;
char b = a;

Explicit occurs when the programmer uses one of three mechanisms in code that can force conversion. These are
referred to as typecasting, and there are three that I can think of:

(new_type) old_type

static_cast < new_type > old_type

dynamic_cast < new_type > old_type

Each one has uses throughout code, it is preferred to use static_cast in lieu of (new_type) old_type. dynamic_cast is generally used in the OOP arena to enable casting up and down the inheritance tree.

Re: How to conversion array to one string...

Posted 10 June 2007 - 10:31 AM

You know Gregory I like to read you occasional posts because I learn a lot. Not really the broad topics but the little things that I have either overlooked or forgotten, or never really understood. I myself have never really known what the difference or reason behind having a static_cast and a dynamic_cast. I just use the standard C cast unless (for example windows programming) it just seems to be what everyone else is doing (i.e. I copied code from somewhere and never changed that line because I didn't really know what it did.)

Though I am nor sure that discussion really helps change an array of integers into a string... Does the string class have a native conversion from integers to strings?

I would think that a loop using a stringstream or an sptrintf() would be the way to go.

Re: How to conversion array to one string...

Help me,
I have problem about method to convert array (type int) to one string (type char),
e.g. input as :
array[1]=1
array[2]=2
array[3]=3
array[4]=4
.
.
.
array[n]=n
stuff of every array are independent.

If i want in the output denote an one string as below :
I am defined variabel name of string is *string than the product is string="1234.....n".

How to implementation solve the problem in the C++ Program.

Thanks.
ImamkomC++

hi

Conversion falls into two categories:

Implicit

Explicit

Implicit occurs when the compiler will allow the conversion and does so at compile time. An integer and a char can be converted implicitly by this code:

int a = 5;
char b = a;

Explicit occurs when the programmer uses one of three mechanisms in code that can force conversion. These are
referred to as typecasting, and there are three that I can think of:

(new_type) old_type

static_cast < new_type > old_type

dynamic_cast < new_type > old_type

Each one has uses throughout code, it is preferred to use static_cast in lieu of (new_type) old_type. dynamic_cast is generally used in the OOP arena to enable casting up and down the inheritance tree.

Hope this helps.

Hi,
I tried to use static_cast for conversion but while displaying using cout it prints garbage value.