C ++ CLI中的MOD和DIV [英] MOD and DIV in C++ CLI

查看:76
本文介绍了C ++ CLI中的MOD和DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我是C ++ / CLI的菜鸟,我想问一个小问题:



我需要得到两个整数变量A和B的MOD和DIV ,



如何用正确的语法和 A = A(MOD)B和A = A(DIV)B 我应该在我的代码中添加一个特殊的标题才能使用它们!???谢谢

解决方案

% - mod

/ - div



  int  i1 =  5  2 ;  //   i1 == 1  
int i2 = 5 / 2 ; // i2 == 2


< blockquote>虽然Simon完全正确,但也有

 ldiv_t ldiv(long int numerator,long int denominator); 



它将分子除以分子的整数商和余数作为 ldiv_t 类型的结构,这个结构有两个成员quot和rem。如果你需要这两个结果,调用ldiv会更有效率。



最好的问候

Espen Harlinn


Hi everyone! I am a noob in C++/CLI, I d like to ask a small question:

I need to get the MOD and the DIV of two integer variables A and B,

How can I do A=A(MOD)B and A=A(DIV)B in the right syntax and... should I add an special header to my code in order to use these!??? THANKS

解决方案

% - mod
/ - div

int i1 = 5 % 2; // i1 == 1
int i2 = 5 / 2; // i2 == 2


While Simon is entirely right there is also

ldiv_t ldiv ( long int numerator, long int denominator );


Which returns the integral quotient and remainder of the division of numerator by denominator as a structure of type ldiv_t, this structure has two members quot and rem. If you need both results calling ldiv is more efficient.

Best regards
Espen Harlinn


这篇关于C ++ CLI中的MOD和DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆