- 12 Kas 2019
- 56
- 13
Merhaba arkadaşlar forumda yeniyim bir konuda yardımcı olmanızı istiyorum benim c++'ta kullanıcı giriş ve kayıt sistemi yapmam gerekiyor kodun birazını yazdım ancak bir yerde takıldım sorun şu kullanıcı kayıt oluyor kayıt olunan veri bir dosyada tutuluyor ve kullanıcı giriş yapmak istediğinde bu dosya okunup eğer kullanıcı bilgileri doğru girerse sistem kabul ediyor ancak bunu sadece 2 satır için yapıyor kullanıcı adı ve şifre satırına ben bunu tüm dosyaya yapmasını istiyorum yani tüm dosyadaki satırları okuyup hafızaya yazıcak ve kullanıcı 2-3 defa kayıt olduğunda istediği kayıtla sisteme giriş yapabilecek kodun tamamı burda yardım edebilir misiniz?
Kod:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
bool Giris()
{
string kullaniciadi, sifre, ka, sif;
cout << "Kullanici Adi: "; cin >> kullaniciadi;
cout << "Sifre: "; cin >> sifre;
ifstream read;
read.open("kayit.txt");
getline(read, ka);
getline(read, sif);
if (ka == kullaniciadi && sif == sifre)
{
return true;
}
else
{
return false;
}
}
int main()
{
int secim;
cout << "1: Kaydol\n2:Giris Yap\nSecimin: "; cin >> secim;
if (secim == 1)
{
string kullaniciadi, sifre;
cout << "Kullanici adi seciniz: ";
cin >> kullaniciadi;
cout << "Sifre seciniz: ";
cin >> sifre;
ofstream file;
file.open("kayit.txt", ios::app);
file << kullaniciadi << endl << sifre << endl;
file.close();
main();
}
else if (secim == 2)
{
bool durum = Giris();
if(!durum)
{
cout << "Yanlis Giris!" << endl;
system("PAUSE");
return 0;
}
else
{
cout << "Basarili bir sekilde giris yaptin!" << endl;
system("PAUSE");
return 1;
}
}
}
Moderatör tarafında düzenlendi: