2017-02-23 24 views
0

当我尝试编译我的代码时,对于抛出错误的问题感到非常困惑。我目前正在试图通过打印出应该从文件中提取的值来测试我编写的函数。Visual Studio 2015:获取“非标准语法,使用'和'创建成员指针”错误

gameboard.cpp

#include "stdafx.h" 
#include <iostream> 
#include <sstream> 
#include <fstream> 
#include "error.h" 

using namespace std; 

int boardDim(ifstream & inputFile, unsigned int x, unsigned int y) { 
    inputFile.open; //error is thrown here 
    if (!(inputFile.is_open())) { 
     throw fileNotOpen; 
    } 
    else { 
     stringstream output(inputFile.getline); //error is also thrown here 
     if (output >> x) { 
      if (output >> y) { 
       return success; 
      } 
      return secBoardVarErr; 
     } 
     return firstBoardVarErr; 
    } 
    cout << x << endl; 
    cout << y << endl; 
} 

gameboard.h

#ifndef GAMEBOARD_H 
#define GAMEBOARD_H 

#include <iostream> 


using namespace std; 

//takes in dimensions of board from file 
int boardDim(ifstream &, unsigned int, unsigned int); 

#endif !GAMEBOARD_H 

主要功能

#include "stdafx.h" 
#include "functions.h" 
#include "gamepieces.h" 
#include "gameboard.h" 
#include "error.h" 

int main(int argc, char * argv[]) 
{ 
    ifstream x("test.txt"); 
    int test = 0; 
    cout << boardDim(x, 0, 0) << endl; 
    return success; 
} 

我只测试函数I声明并在游戏键盘头文件和源定义文件,所以其他包含的文件将在未来使用,但已经过测试,不会丢失编译和运行时出现错误。

谢谢!

+0

'inputFile.open; //在这里抛出错误 - 这不是你在'C++'中调用函数的方式。圆括号在哪里?奇怪的是,你在这里省略了括号,但是没有在'is_open()'函数之后放弃它。 – PaulMcKenzie

+0

@paulMcKenzie,谢谢!我仍然在学习这门语言! – Harrison

回答

0

inputFile.open是一个函数,与inputFile.getline一样,所以你在这里是一个语法错误。正确的语法是:

inputFile.open() 

inputFile.getline() 
+0

非常感谢。我无法相信这是我正在寻找的这个错误,大约一个小时。 – Harrison

+0

@Harrison如果这篇文章已经回答了你的问题,请标记出来。 – arrowd

+0

没问题。请务必提供您认为有帮助的答案。 ;)在你的C++冒险中祝你好运;编译器错误往往是神秘而迷惑的,所以请留意这样的事情。 –

相关问题