Error? help please?

Always error what's wrong with my code?
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 #include <iostream>
#include <fstream>
#include <string>

using namespace std;

bool IsLoggedIn()
{
    string username, password, un, pw;

    cout << "Enter username: "; cin >> username;
    cout << "Enter password: "; cin >> password;

    ifstream read("data\\" + 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\n2: Login\nYour choice: "; cin >> choice;
    if (choice ==1)
    {
        string username, password;

        cout << "select a username: " cin >> username;
         cout << "select a password: " cin >> password;

         ofstream file;
         file.open("data\\" +username + ".txt");
         file << username << endl << password;
         file.close();
    }
    else if (choice == 2)
    {
        bool status = IsLoggeIn();

        if (!status)
        {
            cout << "False Login!" << endl;
            system("PAUSE");
            return 0;
        }
        else
        {
            cout << "Succesfully logged in!" << endl;
            system("PAUSE");
            return 1;
        }
    }
}
Hey =) Please in the future always post your full error message that the compiler gives.

1.
1
2
cout << "select a username: " cin >> username; // missing semicolon before cin
cout << "select a password: " cin >> password; // missing semicolon before cin 


Should be:
1
2
cout << "select a username: "; cin >> username;
cout << "select a password: "; cin >> password;


2.

bool status = IsLoggeIn(); // should be IsLoggedIn, not isLoggeIn. missing the "d".

Edit:
And just a general tip. The else statement in your function is not needed, you can change it to -

1
2
3
4
5
6
if (un == username && pw == password)
    {
        return true;
    }
   return false;
}


which would achieve the exact same thing.
Last edited on
is the file in the same dir as the main file or is it in a diferant file e.g. C:\folder\folder\myfile.txt
and your main file C:\folder\mainfile.cpp
if so you must specify the file dir
hope this helps
but it wold help to know the erorr
Here's the error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
||=== Build: Debug in LoginSystem BYunknown (compiler: GNU GCC Compiler) ===|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp||In function 'bool IsLoggedIn()':|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|14|error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::basic_string<char>)'|
C:\Programming#1\Login system\LoginSystem BYjustin\main.cpp|14|note: candidates are:|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|460|note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|460|note:   no known conversion for argument 1 from 'std::basic_string<char>' to 'const char*'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|446|note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits<char>]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|446|note:   candidate expects 0 arguments, 1 provided|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|420|note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|420|note:   no known conversion for argument 1 from 'std::basic_string<char>' to 'const std::basic_ifstream<char>&'|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp||In function 'int main()':|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|37|error: expected ';' before 'cin'|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|38|error: expected ';' before 'cin'|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|41|error: no matching function for call to 'std::basic_ofstream<char>::open(std::basic_string<char>)'|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|41|note: candidate is:|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|702|note: void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|702|note:   no known conversion for argument 1 from 'std::basic_string<char>' to 'const char*'|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|47|error: 'IsLoggeIn' was not declared in this scope|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|52|error: 'system' was not declared in this scope|
C:\Programming#1\Login system\LoginSystem BYunknown\main.cpp|58|error: 'system' was not declared in this scope|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Last edited on
Topic archived. No new replies allowed.