【问题标题】:Hello World C++ error - cmathHello World C++ 错误 - cmath
【发布时间】:2015-08-26 08:57:50
【问题描述】:

我是 C++ 的完全初学者。我正在使用带有 fltk 1.3.x 的 Microsoft Visual Studio 2015,并且正在遵循 Bjarne Stroustrup 的“使用 C++ 的编程原理和实践”。我目前正在做的程序是 Hello World,p52-54 上的练习。

我编写的代码(/从书中复制以及 std_lib_facilities.h [www.stroustrup.com/Programming/include-std_lib_facilities.doc] 的支持文档)是:

//My first hello world program
#include "../../../std_lib_facilities.h"
int main()  //C++ programs start by executing the function main
{
    cout << "Hello, World!/n";  //output "Hello, world!"
    keep_window_open();         //wait for a character to be entered
    return 0;
}

然后我去构建 -> 编译,这会发生......

Severity    Code    Description Project File    Line
Error (active)      the global scope has no "acosf" Hello_World c:\Program      Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath   670
Error (active)      the global scope has no "asinf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    670
Error (active)      the global scope has no "atanf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    671
Error (active)      the global scope has no "atan2f"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    671
Error (active)      the global scope has no "ceilf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    671
Error (active)      the global scope has no "cosf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    672
Error (active)      the global scope has no "coshf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    672
Error (active)      the global scope has no "expf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    672
Error (active)      the global scope has no "fabsf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    673
Error (active)      the global scope has no "floorf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    673
Error (active)      the global scope has no "fmodf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    673
Error (active)      the global scope has no "frexpf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    674
Error (active)      the global scope has no "ldexpf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    674
Error (active)      the global scope has no "logf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    674
Error (active)      the global scope has no "log10f"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    675
Error (active)      the global scope has no "modff" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    675
Error (active)      the global scope has no "powf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    675
Error (active)      the global scope has no "sinf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    676
Error (active)      the global scope has no "sinhf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    676
Error (active)      the global scope has no "sqrtf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    676
Error (active)      the global scope has no "tanf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    677
Error (active)      the global scope has no "tanhf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    677
Error (active)      the global scope has no "acosl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    679
Error (active)      the global scope has no "asinl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    679
Error (active)      the global scope has no "atanl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    680
Error (active)      the global scope has no "atan2l"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    680
Error (active)      the global scope has no "ceill" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    680
Error (active)      the global scope has no "cosl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    681
Error (active)      the global scope has no "coshl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    681
Error (active)      the global scope has no "expl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    681
Error (active)      the global scope has no "fabsl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    682
Error (active)      the global scope has no "floorl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    682
Error (active)      the global scope has no "fmodl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    682
Error (active)      the global scope has no "frexpl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    683
Error (active)      the global scope has no "ldexpl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    683
Error (active)      the global scope has no "logl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    683
Error (active)      the global scope has no "log10l"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    684
Error (active)      the global scope has no "modfl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    684
Error (active)      the global scope has no "powl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    684
Error (active)      the global scope has no "sinl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    685
Error (active)      the global scope has no "sinhl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    685
Error (active)      the global scope has no "sqrtl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    685
Error (active)      the global scope has no "tanl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    686
Error (active)      the global scope has no "tanhl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    686
Error (active)      the global scope has no "float_t"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    688
Error (active)      the global scope has no "double_t"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    688
Error (active)      the global scope has no "nan"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    700
Error (active)      the global scope has no "acoshf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    704
Error (active)      the global scope has no "asinhf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    704
Error (active)      the global scope has no "atanhf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    704
Error (active)      the global scope has no "cbrtf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    705
Error (active)      the global scope has no "erff"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    705
Error (active)      the global scope has no "erfcf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    705
Error (active)      the global scope has no "expm1f"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    706
Error (active)      the global scope has no "exp2f" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    706
Error (active)      the global scope has no "hypotf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    707
Error (active)      the global scope has no "ilogbf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    707
Error (active)      the global scope has no "lgammaf"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    707
Error (active)      the global scope has no "log1pf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    708
Error (active)      the global scope has no "log2f" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    708
Error (active)      the global scope has no "logbf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    708
Error (active)      the global scope has no "llrintf"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    709
Error (active)      the global scope has no "lrintf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    709
Error (active)      the global scope has no "nearbyintf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    709
Error (active)      the global scope has no "rintf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    710
Error (active)      the global scope has no "llroundf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    710
Error (active)      the global scope has no "lroundf"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    710
Error (active)      the global scope has no "fdimf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    711
Error (active)      the global scope has no "fmaf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    711
Error (active)      the global scope has no "fmaxf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    711
Error (active)      the global scope has no "fminf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    711
Error (active)      the global scope has no "roundf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    712
Error (active)      the global scope has no "truncf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    712
Error (active)      the global scope has no "remainderf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    713
Error (active)      the global scope has no "remquof"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    713
Error (active)      the global scope has no "copysignf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    714
Error (active)      the global scope has no "nanf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    714
Error (active)      the global scope has no "nextafterf"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    715
Error (active)      the global scope has no "scalbnf"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    715
Error (active)      the global scope has no "scalblnf"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    715
Error (active)      the global scope has no "nexttowardf"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    716
Error (active)      the global scope has no "tgammaf"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    716
Error (active)      the global scope has no "acoshl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    718
Error (active)      the global scope has no "asinhl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    718
Error (active)      the global scope has no "atanhl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    718
Error (active)      the global scope has no "cbrtl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    719
Error (active)      the global scope has no "erfl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    719
Error (active)      the global scope has no "erfcl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    719
Error (active)      the global scope has no "expm1l"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    720
Error (active)      the global scope has no "exp2l" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    720
Error (active)      the global scope has no "hypotl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    721
Error (active)      the global scope has no "ilogbl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    721
Error (active)      the global scope has no "lgammal"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    721
Error (active)      the global scope has no "log1pl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    722
Error (active)      the global scope has no "log2l" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    722
Error (active)      the global scope has no "logbl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    722
Error (active)      the global scope has no "llrintl"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    723
Error (active)      the global scope has no "lrintl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    723
Error (active)      the global scope has no "nearbyintl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    723
Error (active)      the global scope has no "rintl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    724
Error (active)      the global scope has no "llroundl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    724
Error (active)      the global scope has no "lroundl"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    724
Error (active)      the global scope has no "fdiml" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    725
Error (active)      the global scope has no "fmal"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    725
Error (active)      the global scope has no "fmaxl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    725
Error (active)      the global scope has no "fminl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    725
Error (active)      the global scope has no "roundl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    726
Error (active)      the global scope has no "truncl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    726
Error (active)      the global scope has no "remainderl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    727
Error (active)      the global scope has no "remquol"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    727
Error (active)      the global scope has no "copysignl" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    728
Error (active)      the global scope has no "nanl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    728
Error (active)      the global scope has no "nextafterl"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    729
Error (active)      the global scope has no "scalbnl"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    729
Error (active)      the global scope has no "scalblnl"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    729
Error (active)      the global scope has no "nexttowardl"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    730
Error (active)      the global scope has no "tgammal"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    730
Error (active)      the global scope has no "fpclassify"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    732
Error (active)      the global scope has no "signbit"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    732
Error (active)      the global scope has no "isfinite"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    733
Error (active)      the global scope has no "isinf" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    733
Error (active)      the global scope has no "isnan" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    734
Error (active)      the global scope has no "isnormal"  Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    734
Error (active)      the global scope has no "isgreater" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    735
Error (active)      the global scope has no "isgreaterequal"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    735
Error (active)      the global scope has no "isless"    Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    736
Error (active)      the global scope has no "islessequal"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    736
Error (active)      the global scope has no "islessgreater" Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    737
Error (active)      the global scope has no "isunordered"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath    737
Error (active)      cannot open source file "/usr/include/math.h"   Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\math.h   22
Error   C1083   Cannot open include file: '/usr/include/math.h': No such file or directory  Hello_World c:\program files (x86)\microsoft visual studio 14.0\vc\include\math.h   22
Error (active)      linkage specification is incompatible with previous "copysign" (declared at line 53 of "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\math.h") Hello_World c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xtgmath.h    183
Error (active)      linkage specification is incompatible with previous "rint"     (declared at line 52 of "c:\Program Files (x86)\Microsoft Visual Studio     14.0\VC\include\math.h") Hello_World c:\Program Files (x86)\Microsoft Visual     Studio 14.0\VC\include\xtgmath.h    207

我认为这与 std_lib_facilities.h 文件有关。本书推荐使用 fltk 1.1.x 和 Visual Studio 2005,所以这可能也是问题的一部分?

非常感谢您提供的任何见解。

谢谢。

【问题讨论】:

  • 刚刚尝试在 VS2015 (w/o fltk) 中使用std_lib_facilities.h 并且示例有效。
  • cout &lt;&lt; "Hello, World!/n"; 将输出“Hello, world!/n”,而不是“Hello, world!”换行
  • 2 看起来可疑的东西。 1.) 我没有文件“c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\math.h”,并且我的任何文件中都没有包含此文件。 2.) cannot open source file "/usr/include/math.h" 不应出现在 Windows 上。 ||你能解释一下吗?
  • 看起来不错。尝试运行程序。
  • @user5267538 我认为您的依赖项设置不正确。为什么不从头开始尝试建立一个新项目呢?

标签: c++


【解决方案1】:

应该可以的

#include <iostream>

int main()

{

    std::cout << "Hello, World!" << std::endl;   //endl = /n

    system("pause")      //system pause = wait till user entering a char

    return 0;

}

【讨论】:

    【解决方案2】:

    我也很新,但这是我使用 Visual Studio 的方法:


    // my first program in c++
    
    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
    
    cout <<"Hello World! I am a c++ program.";
    
        return 0;
    }
    

    基本上你只需要使用#include 这将告诉计算机使用这些功能来执行程序(去掉空格)。 您还需要包括: using namespace std;如果你想说“cout”。否则,您必须在 cout 之前指定并说出 std。 最后,您可以取出“保持窗口打开的东西”。你不需要,只要你点击 CTRL-F5 来运行程序。 希望有帮助! 祝你好运!

    【讨论】:

    • 此代码不起作用。使用#include &lt;iostream&gt; 而不是Hashtag include &lt; iostream &gt;
    • 不,它确实有效。显然你应该使用实际的 # 而不是这个词。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 2011-08-26
    • 1970-01-01
    • 2017-03-20
    相关资源
    最近更新 更多