在VS Code中编译c ++脚本时,编译器不会出错,而使用CodeBlocks编译时不会出错

时间:2018-11-12 14:08:09

标签: c++ visual-studio-code g++ codeblocks

那是我正在处理的代码:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main() {
    srand(time(0));

    int a = rand() % 6 + 1;
    int b = rand() % 6 + 1;
    int c = rand() % 6 + 1;
    cout << "a: " << a <<" b: " << b <<" c: " << c << endl;

    if(a < b && a < c){
        cout << a << " is the lower" << endl;
    }
    else if(b < c){
        cout << b << " is the lower" << endl;
    }
    else{
        cout << c << " is the lower" << endl;
    }
    return 0;
}

使用VS CODE程序编译时,显示的结果没有错误。

当我尝试使用CodeBlocks编译器运行代码时,输​​出以下消息:

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\****1_2.cpp||In function 'int main()':|
C:\****1_2.cpp|15|error: 'nullptr' was not declared in this scope|
C:\****1_2.cpp|15|error: 'srand' was not declared in this scope|
C:\****1_2.cpp|17|error: 'rand' was not declared in this scope|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

0 个答案:

没有答案