Logo

רד-בורד: ארכיון

ראשי > תיכנות > תכנות לקבצים בסיפיפי...

2004-07-04 02:21 coolz

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>


void ingore()
{
cin.ignore(1,'<');
cin.ignore(1,'>');
cin.ignore(1,'?');
cin.ignore(1,'~');
cin.ignore(1,'!');
cin.ignore(1,'@');
cin.ignore(1,'#');
cin.ignore(1,'$');
cin.ignore(1,'%');
cin.ignore(1,'^');
cin.ignore(1,'&');
cin.ignore(1,'*');
cin.ignore(1,'(');
cin.ignore(1,')');
cin.ignore(1,'{');
cin.ignore(1,'[');
cin.ignore(1,'}');
cin.ignore(1,'}');
cin.ignore(1,',');
cin.ignore(1,'.');
cin.ignore(1,'');
cin.ignore(1,':');
}

//I'd created Class for the user login.
class Login
{

public:
char UserName[30];
int Password;
};

int main(int argc, char *argv[])
{
int x;

cout <<"1. Login." << endl;
cout << "2. New user." << endl;
cin >> x;
switch(x)
{
case (1): //First case.
{
Login Member; //I'd created object for the class.
cout << "Hello, please enter your UserName" << endl;
cin.get(Member.UserName,30); //get the full username (I'd used cin.get because there is a case of spcaces).
cout << "Thank you.
Please enter your Password:" << endl;
cin >> Member.Password;
if ( (Member.UserName == "cool zero") && (Member.Password == 1234) )
{
cout << "Hey there, your Info:
" << endl;
cout.width(15); //Make same spaces for the cout.fill.
cout.fill('*'); //Fills Blanked spaces.
cout << "User name:" << Member.UserName;
cout.width(15);
cout.fill('*');
cout << "
Password:" << Member.Password;
cout.width(15);
cout.fill('*');
}
else

{
cout << "aWorng Password/Username." << endl;
}
break;
}

//Next case.
case(2):
{
Login Users;
ofstream fout("Users.txt");
cout << "Welcome to users admistrtion." << endl;
cout << "Please enter user name
";
void ignore();
cin.get(Users.UserName,30);
fout << Users.UserName << ":";
cout << "Please entrer your password
";
cin >> Users.Password;
fout << Users.Password << "
";
fout.close(); //Closeing file.
break;

}

//Default case.
default:
{
cout << "No such option" << endl;
break;
}

}
return EXIT_SUCCESS;
}




תסתכלו רק על הקייס ה2... התעצלתי לעשות תחיפוש בקובץ.. לא שזה בעיה פשוט עוד 3 שורות.. בלעע בכל מקרה שאני מריץ מה שקורה זה שהוא זורק לי את כל הפלט ולא מחכה לקבלת הפלט... זה מורץ על
KDevelop


הנה דוגמת הרצה:

Press Enter to continue!1. Login.
2. New user.
2
Welcome to users admistrtion.
Please enter user name
Please entrer your password

Press Enter to continue!

בתודה מראש קולז.

[נערך על-ידי coolz בתאריך 2004/07/04 02:23][נערך על-ידי silicon_wolf בתאריך 2004/07/04 02:25]
עמודים: 1