c·c++/c++ 프로그래밍

패스워드 파일을 읽고 처리하는 간단한 예제

바로이순간 2012. 5. 29. 00:43



#include <fstream>

#include <iostream>

using namespace std;

int main() {

    ifstream inf("login.txt");

    

    if(!inf) {

        cerr<<"login.txt 파일을 읽을 수 없습니다."<<endl;

        return 1;

    }

    string one, two, logTable[10][2];

    int i=0, n=0;

    inf >> one >> two;

    while(inf) {

        logTable[i][0]=one;

        logTable[i][1]=two;

        cout << logTable[i][0] << " " << logTable[i][1] << endl;

        inf >> one >> two;

        i=i+1;

    }

    n=i;

    

    while(1) {

        int gotit=0;

        cin>>one;

        if(one=="q") break;

        cin>>two;

        // cout<<one<<" "<<two<<endl;

        gotit=0;

        for(i=0;i<n;++i) 

            if(logTable[i][0]==one && logTable[i][1]==two) 

                gotit=1;

        if(gotit>0) cout<<"GotIt."<<endl;

        else cout<<"Wrong."<<endl;

    }

    return 0;

}



'c·c++ > c++ 프로그래밍' 카테고리의 다른 글

getline  (0) 2012.08.16
숫자열에서 한숫자씩 입력받기  (0) 2012.07.08
sstream의 활용 - sscanf   (0) 2012.05.16
소수점이 포함된 진법변환  (0) 2012.04.24
열린 문의 갯수  (0) 2012.04.16