Reading a TXT line into a string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void login() {
//username, password, option to register, option to exit, link to website

    cout << "Would you like to login(1), or press anything else to register.?" << endl;
    cin >> loginYorN;

    if (loginYorN == 1) {
        cout << "Please enter your username: ";
        cin >> accountInfo[1];
        cout << endl << "Please enter your password: ";
        cin >> accountInfo[2];

        ifstream login;
        login.open ("login.csv");
        if(accountInfo[1] == acountID && accountInfo[2] == accountPW) {
            worldSelect();
        } else {
            cout << "Please try again, as you have enter the wrong information." << endl;
            login();
            //check if login details match what they inputted
            login.close;
        }
        login.close;
    } else {
        reigsterAccount();
    }
}


So as above, I ask them to input 1 for login, anything else for register. Whatever they input, it get's stored into loginYorN, then I check to see what they input. If they put '1' for input, then I ask them for their username, store that into accountInfo[1], and then asking for the password, storing that into accountInfo[2].

Now here is where I need to input line 1(username) from login.csv or login.txt and line2(password) and storage these into accountID and accountPW.

Ive tried taken several routes with this, have yet to find something that works. Hoping I get something good here.
Read the csv file one line at a time.
Parse out the comma separated fields.
If there are just two fields then it would be something like this:
1
2
3
4
5
string line;
login.getline(line);
size_t commaPos = line.find(',');
accountID = line.substr(0,commaPos-1);
accountPW = line.substr(commaPos+1, line.size()-commaPos-1);
Topic archived. No new replies allowed.