Converting from C++ to C#

G

Guest

I am converting a C++ application to C#, What in C# replaces the following
C++ functions:
overloaded opertaor=

_ecvt(Math.Abs(val),14,&dec,&sign) ; //this function converts a double to a
string & puts the position of the decimal point & the sign of value in the
dec & sign paramaters, and it lets you specify how many digits you want to
store in the string(14)

I noticed that the C# math library only has an abs() method not a fabs()
method, what would replace the fabs method?

What is used in C# to replace sprintf?

Thanks
 
D

Daniel O'Connell [C# MVP]

rgarf said:
I am converting a C++ application to C#, What in C# replaces the following
C++ functions:
overloaded opertaor=

Nothing, C# doesn't allow overriding the assignment operator.
_ecvt(Math.Abs(val),14,&dec,&sign) ; //this function converts a double to
a
string & puts the position of the decimal point & the sign of value in the
dec & sign paramaters, and it lets you specify how many digits you want to
store in the string(14)

I don't understand waht you are asking here.
I noticed that the C# math library only has an abs() method not a fabs()
method, what would replace the fabs method?

Math.Abs deals with integers and floating point numbers, does fabs offer
anything else?
What is used in C# to replace sprintf?

String.Format is the closet function.
 
G

Guest

The _ecvt function converts a double to string. This function stores up to
count digits of a value as a string,
The position of the decimal point and the sign of value can be obtained from
dec and sign after the call.
_ecvt(Math.Abs(val),14,&dec,&sign);
So how can I do this function call in C#, since C# does not have the _ecvt
function.

there is an append function on a string in C++, that appends a string to
another string starting at a specific position & the user can specify how
many elements to append, for example:
str1.append(str2, 1, 2);
What method in C# replaces the C++ append function?

There is a function in C++ to convert an interger to a string:
_itoa(deg, bufdeg, 10) ;
What is used in C# to replace this funtion _itoa?

Thanks
 
D

Daniel O'Connell [C# MVP]

rgarf said:
The _ecvt function converts a double to string. This function stores up to
count digits of a value as a string,
The position of the decimal point and the sign of value can be obtained
from
dec and sign after the call.
_ecvt(Math.Abs(val),14,&dec,&sign);
So how can I do this function call in C#, since C# does not have the _ecvt
function.

I don't know about how to retreive the sign and decimal point location, but
getting a string is simply an issue of calling ToString on your double
variable.
there is an append function on a string in C++, that appends a string to
another string starting at a specific position & the user can specify how
many elements to append, for example:
str1.append(str2, 1, 2);
What method in C# replaces the C++ append function?

Depending on what you want, the various String and StringBuilder method's
will do what you want. There isn't one single method
There is a function in C++ to convert an interger to a string:
_itoa(deg, bufdeg, 10) ;
What is used in C# to replace this funtion _itoa?

the ToString() method on the int.

You should really read up on the framework, most of these questions are
quite elementary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top