65.9K
CodeProject 正在变化。 阅读更多。
Home

C# 转换类,支持 C++ 等

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.16/5 (11投票s)

2004年5月28日

1分钟阅读

viewsIcon

55526

downloadIcon

490

ConvertTo、Math、Stack 类,让您在使用 C++ 6.0 时更加轻松。

引言

我以前用 C++ 6.0 编程很长时间了,当 C# 出现时我并不喜欢它,但当我开始使用它时,我感觉很舒服,因为所有相关的函数都组合在一起,比如有一个类包含所有转换函数,一个类包含所有数学函数,还有一个堆栈类,这些类有很多我们需要的函数,但我们没有时间自己编写。所以,因为我仍然热爱 C++,因为它仍然是世界上功能最强大的编程语言,所以我从 C++ 头文件中提取了一些函数,并自己编写了一些函数,将它们组合在一个 LIB 文件和一些头文件中。

Using

要使用此 LIB,请将其粘贴到您的解决方案文件夹中。然后在 VC++6.0 菜单中(项目 -> 设置)

在“链接”选项卡中的“(对象/库模块)”框中,输入库的名称,例如 (CSharp.lib)

然后使用“添加文件到项目”将头文件添加到您的项目工作区,然后在您的 cpp 文件中包含头文件的名称,如下所示

 

#include "Math.h";


我认为所有函数都清晰明了,并且在 C++ 和 C# 中具有相同的名称。

但我会讨论一下它们

 

--------------------------------------------------------------------------------


Cconvert 类包含所有基本数据类型转换,例如 (int、double、float、long、byte、bool、Cstring)

Cconvert x;int i=19;
x.ToDouble(i);
x.ToString (i,4); //4 mean the digits number that you want to apear to user
//and so on...


--------------------------------------------------------------------------------


CIntStack 类接收整数并将它们放入动态增加的堆栈中

 

CIntStack  s;
s.Push(6);
s.Push(7);
s.GetCount() ; //get the number of stack Elements.
Int buff=s.Pop();//buff =7;
buff= s.Pop();//buff=6;
buff=s.Pop();//buff=-1;

 

您还会找到 CstringStack 和 CdoubleStack,它们具有相同的函数

 

--------------------------------------------------------------------------------


CMath 类包含所有我们需要的数学函数,以及一些其他函数。

 

CMath m;
m.Round(9.6);
m.Ceil(8.6);
m.Sin(2.7);//takes radians 
m.SinD(90);//takes Degree;
m.Mean(arr,size);//get the mean of array;
m.Median (arr,size);//get the Median of array;
m.Sort(arr,10);//Sort integer and double arrays and take the size of array
m.LinearSearch(arr,key,size);//key to be search with it and take double too;
m.BinarySearch(arr,key,size);//this function call sort function frist to sort the array ,and //take double
m.GetMaxInArray(arr,size);//get the max number in array int or double ,
m.GetMaxIndexInArray(arr,size);//get the index that have the max number.
m.GetMax(var1,var2,var3);//get the max between three numbers and also two number.
///and you will find also GetMin  functions like GetMax;and all regular math function //that you will need.

 


希望您喜欢它,如果遇到任何问题请告诉我。

© . All rights reserved.