本文介绍了%与FMOD的关系以计算模量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制台应用看起来像这样.

My console app looks like that.

#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int a, b;
    cin>>a>>b;
    cout<<"% "<<a%b<<endl<<"fmod "<<fmod(a,b)<<endl;
    system("pause");
    return 0;
}

我是C ++的新手,我有2个问题:

I'm newbie to C++ and I got 2 questions:

  1. 在VS上编写此应用程序.为什么需要包含"stdafx.h"?有什么要求吗?这是什么?
  2. fmod%之间是否有区别?为他们获得完全相同的结果:
  1. Writing this application on VS. Why do I need to include "stdafx.h"? Is there any requirement? What is this?
  2. Is there any difference between fmod and % ? Getting exactly same results for them:

提前谢谢.

推荐答案

因为默认项目设置表明您需要预编译的标头(请参见).

Because the default project setting says you need precompiled header (See this).

您可以手动禁用它.选择不使用预编译头文件,如下图所示:

You can disable this manually. Select Not Using Precompiled Headers as shown in the image below:

是的. %不能对浮点数进行操作,而fmod可以. fmod 中的f表示浮点.

Yes. % cannot operate on floating-pointer numbers, while fmod can. f in fmod indicates floating-point.

尝试一下:

float a, b;
std::cin>>a>>b;
std::cout << (a%b) << std::endl; //it will give compilation error.

这篇关于%与FMOD的关系以计算模量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 10:37