Turbo C++ Login Program

I made a login program on CppDroid then tried to reconstruct it for turbo c++ 3.2 use, well, i failed. So can someone give me hints on getting this right.

Here's my code it works yeah but not on turbo c++ :(
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
    #include <iostream>
//#include <iostream.h>
//#include <conio.h>
//#include <string.h>
using namespace std;

int main()
{
    string use = "", pass = "";
    string user, password;
    int i;
    
    user = "admin";
    password = "1234";

    for (i = 0; i < 3; i++)
    {
        //clrscr();
        cout << "Please enter username: ";
        cin >> use;
        cout << "\nPlease enter password: ";
        cin >> pass;
        
        if (use == user && pass == password)
        {
            cout << "\nWelcome -insert- to Infinity Tower!";
            //getch();
            return 0;
        }
        else if(i > 2)
        {
            return 1;
        }
    }
}
I don't think Turbo C++ knows anything about namespace std. More problematic, I don't think it has the string class that is part of standard C++. Back in those dusty ancient days when Turbo C++ was written for DOS and later the new-fangled Windows 3.1, such things had hardly been dreamed of - at least they were not standardised at that time.
Yes i just learned that when browsing through forums. I tried it using array, can't get it to work properly using arrays.
Using char arrays is how they handled strings in C so you can probably find more about it if you study some C resources.

For comparing two char arrays you probably want to use the strcmp function.
http://www.cplusplus.com/reference/cstring/strcmp/

For copying strings you could use the strcpy function.
http://www.cplusplus.com/reference/cstring/strcpy/

Note that you need to be much more careful when doing it this way. Arrays don't automatically resize themselves so you have to make sure you make them large enough.
Last edited on
You need to use the C-string functions such as strcpy(), strcmp() etc
http://www.cplusplus.com/reference/cstring/strcpy/
http://www.cplusplus.com/reference/cstring/strcmp/

Tested on TC 3.0
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
#include <iostream.h>
#include <conio.h>
#include <string.h>


int main()
{
    char use[30]  = "";
    char pass[30] = "";
    char user[30];
    char password[30];
    int i;

    strcpy(user, "admin");
    strcpy(password, "1234");

    for (i = 0; i < 3; i++)
    {
        clrscr();
        cout << "Please enter username: ";
        cin >> use;
        cout << "\nPlease enter password: ";
        cin >> pass;

        if ( !strcmp(use, user) && !strcmp(pass, password) )
        {
            cout << "\nWelcome " << use << " to Infinity Tower!";
            getch();
            return 0;
        }
        else if (i > 2)
        {
            return 1;
        }
    }
    return 0;
}
Last edited on
Thanks for the answers and references, really helped me understand strings in old compilers.
Topic archived. No new replies allowed.