2010-11-26 3 views
9

37 번째 줄에있는 fstream을 사용하여 파일을 읽는 중 오류가 발생하지만 (fstream grabpass ("passwords.txt");) 나는 보이지 않습니다. 잘못하고있는 것.변수 'fstream grabpass'에 이니셜 라이저가 있지만 불완전한 유형이 있습니다

#include <iostream> 
#include <conio.h> 
#include <string> 

using namespace std; 

int i,passcount,asterisks; 
char replace, value, newchar; 
string username,password,storedUsername,storedPassword; 

int login(string username, string password) 
{ 
    if (username=="test"/*storedUsername*/) 
    { 
     if (password==storedPassword) 
     cout<<"Win!"; 
     else 
     cout<<"Username correct, password incorrect."; 
    } 
    else cout<<"Lose. Wrong username and password."; 
} 

int main() 
{ 
    cout<<"Username: "; 
    cin>>username; 
    cout<<"Password: "; 
    do 
    { 
    newchar = getch(); 
    if (newchar==13)break; 
    for (passcount>0;asterisks==passcount;asterisks++)cout<<"*"; 
    password = password + newchar; 
    passcount++; 
    } while (passcount!=10); 

    fstream grabpass("passwords.txt"); 
    getline(grabpass,storedPassword); 
    grabpass.close(); 
    login(username,password); 

    return 0; 
} 

답변

18

#include <fstream>을 추가해야합니다. 아마도 <iostream>fstream (대부분은 <iosfwd>을 닮음)의 선언을 포함하지만 정의는 포함하지 않으므로 해당 유형의 객체를 정의하려고 할 때 불완전한 유형을 갖습니다.

+0

Erm. 내가 왜 그렇게하지 않았어 ... 고마워, 제리. 내 멍청한 실수. –

관련 문제