jeudi 26 mai 2016

Error: No matching function?

The problem is, I keep getting this error > error: no matching function for call to 'std::basic_ifstream::basic_ifstream(std::basic_string)'

and >error: no matching function for call to 'std::basic_ofstream::open(std::basic_string)'

How do I fix this?

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

bool loginOn(){

string username, password, un, pw;
cout << "Username > ";
cin >> username;
cout << "Password > ";
cin >> password;

ifstream read("c:\\" + username + ".txt");
getline(read, un);
getline(read, pw);

if ( un == username && pw == password){
    return true;
}
else{
    return false;
}
}

int main(){

int choice;

cout << "1: Register" << endl;
cout << "2: Login" << endl;
cout << "Your chouce > ";
cin >> choice;

if (choice == 1){

    string username, password;
    cout << "Choose username > ";
    cin >> username;
    cout << "Choose password > ";
    cin >> password;

    ofstream file;
    file.open("c:\\" + username + ".txt");
    file << username << endl << password;
    file.close();

    main();
}
else if (choice == 2){
    bool status = loginOn();

    if (!status){
        cout << "Wrong login information" << endl;
        system("PAUSE");
        return 0;
    }
    else{
        cout << "Congratulation! You've login successfully" << endl;
        system("PAUSE");
        return 1;
    }
}
}

Aucun commentaire:

Enregistrer un commentaire