相同的代码在Dev C++上编译,但在Visual Studio 2017上不编译

0 c++ visual-studio-2017

#include<cstdlib>           //Required for compatibility
#include<cmath>             //Required for pow
#include<fstream>           //Required for data files
#include<iostream>          //Required for cout and cin
#include<iomanip>           //Required for setw

using namespace std;

int choice, loops, count;
double initTime, timeIncrement, finalTime, time, A1, B1, C1, D1, E1, 
altitude, A2, B2, C2, D2, E2, velocity;         //This is line 20 as the error notes            
//Declare variables
ifstream inFile;
ofstream outFile;


void menuFunction() {                                                                               
//Main menu function where user selects which option they would like to proceed with, not relevant to question
}

double altitudeFunction(double& altitude) {                                                                         
//Altitude calculation
     altitude = A1 * pow(time, 4.0) + B1 * pow(time, 3.0) + C1 * pow(time, 2.0) + D1 * time + E1; //This is line 36 as the error notes
}

double velocityFunction(double& velocity) {                                                                         
//Velocity calculation
     velocity = A2 * pow(time, 4.0) + B2 * pow(time, 3.0) + C2 * pow(time, 2.0) + D1 * time + E1; // This is line 41, as the error notes
}

void parameters() {                                                                     
//Function to enter time parameters to save space, not relevant to errors      
}

int main() {
    menuFunction();

    while (choice != 4) {
        switch (choice) {

        case 1: {
            parameters();
            if (finalTime < 5 || finalTime > 24) {                                  
 //Required invalid entry error message                                             
//Redisplay menu to allow user another try
            }
            else {
               //Open input file for option 1
               //Find variables in input file
               //close input file and open output file                                                      
              //Make output file look neat
            //Column headers for output file for readability
                loops = (int)((finalTime - initTime) / timeIncrement);
                for (count = 0; count <= loops; count++) {                                      //For loop for incremental calculations, this is line 86 as the error notes
                time = initTime + count * timeIncrement;                                                                
                 //Run both calculation functions
                 //Print results to output file during for loop
            }
            //close output file
            system("CLS");
            //Print message to screen saying data was recorded to output file
        }
        break;
    }

    case 2: {
        parameters();
            if (finalTime < 5 || finalTime > 24) {                                  
 //Required invalid entry error message                                             
//Redisplay menu to allow user another try
            }
            else {
               //Open input file for option 1
               //Find variables in input file
               //close input file and open output file                                                      
              //Make output file look neat
            //Column headers for output file for readability
                loops = (int)((finalTime - initTime) / timeIncrement);
                for (count = 0; count <= loops; count++) {                                      //For loop for incremental calculations, this is line 118 as the error notes
                time = initTime + count * timeIncrement;                                                                
                 //Run both calculation functions
                 //Print results to output file during for loop
            }
            //close output file
            system("CLS");
            //Print message to screen saying data was recorded to output file
        }
        break;
    }

    case 3: {
    parameters();
            if (finalTime < 5 || finalTime > 24) {                                  
 //Required invalid entry error message                                             
//Redisplay menu to allow user another try
            }
            else {
               //Open input file for option 1
               //Find variables in input file
               //close input file and open output file                                                      
              //Make output file look neat
            //Column headers for output file for readability
                loops = (int)((finalTime - initTime) / timeIncrement);
                for (count = 0; count <= loops; count++) {                                      //For loop for incremental calculations, this is line 150 as the error notes
                time = initTime + count * timeIncrement;                                                                
                 //Run both calculation functions
                 //Print results to output file during for loop
            }
            //close output file
            system("CLS");
            //Print message to screen saying data was recorded to output file
        }
        break;
    }

    default: {
        cout << "\tInvalid Entry!\n\n";                                     //Error message if user enters an invalid menu option
        menuFunction();
    }
    }
}

    if (choice == 4) {
       //end program
        system("pause");
        return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的第一个学期的C++编码中,我不明白为什么但是由于某种原因,当我运行这个确切的程序时,它在Dev C++中编译得很好但我在Visual Studio 2017中遇到了许多错误.我试图复制并粘贴错误,但它没有正确格式化,所以基本上每个"时间"和"计数"的实例都给我一个错误,说"'时间/计数'是模糊的"以及以下不常见的错误:

错误C2659'=':用作左操作数86,118,150

错误C2365'时间':重新定义:先前的定义是'功能'20

错误C2297'*':非法,右操作数的类型为'time_t(__ cdecl*)(time_t*const)'36,41

错误C2665'pow':6个重载中没有一个可以转换所有参数类型36,41

该程序应该从输入文件中提取气象气球数据输入,做一些数学计算以获得特定时间的高度和速度值,并将这些值输出到新的数据文件.它在Dev C++上编译,运行和完美运行,但不能在Visual Studio上编译.我只是问,因为我提交了这个课程,因为它没有在教授的计算机上编译,所以给了0,但我的工作正常.有任何想法吗?

编辑删除我的名字以及代码的不相关部分.代码中的注释替换的所有内容都可以正常工作,包含错误的代码部分得以保留.

Bo *_*son 10

这可能表明为什么using namespace std;是一个坏主意的一个原因.

标准库包含一个由std::time函数引入的函数using.

现在编译器不知道plain是否time意味着::time在这个程序或std::time函数中声明的变量.

可能在某些系统上编译的原因是允许C++标准头部间接包含任何其他标准头.因此,可能会发生与Dev-C++偶然使用的标准库头不包括在内std::time.