2017-01-22 90 views
1

不確定錯誤在這裏。這是我以前一直使用的標準文件打開方式。正確的東西正在被包括在內。這只是一個普通的流媒體。這有什麼問題?錯誤:「文件」之前的預期初始化程序,包括ifstream。

#include <iostream> 
#include <fstream> 
#include <sstream> 

using namespace std; 

int main(){ 

struct item{ 
    string item; 
    string type; 
    int price; 
    } 

ifstream board; 
board.open("messageBoard.txt"); 

} 
+0

確保編譯? – Raindrop7

+0

'int price; }'缺少分號 –

+0

答案:結構的末尾也需要分號。哎呀。 – grilam14

回答

1

哇!沒有人可以注意到?? !!

int main(){ 

struct item{  // 
    string item; // error C2580: redefinition of class name 'item' 
    string type; 
    int price; 
    } // missing a semicolon here `;` 

您正在使用的類名作爲另一個標識符,所以你得到一個編譯時錯誤redefinition

這樣就可以使他們不同:

struct Item // 
{ 
    string item; // now it's ok Item is not item 
    string type; 
    int price; 
}; 
相關問題