C++でファイル操作を学んでいます。テストのために、この小さなコードを書きました。基本的に私がやりたいことは、ファイル処理を使用してユーザー アカウント プログラムを作成することです。if else
そのため、プログラムでorを使用while
して、ファイル内のデータを比較したいと考えています。
たとえば、ユーザーが自分のユーザー名を「john」と入力すると、プログラムはファイル内で john という名前を検索できる必要があり、存在する場合は、ユーザーがサインインしてパスワードを使用できるようにする必要があります。
私が書いたコードは単なるファイル書き込みテストです。実際のコードで私を助けてください。初心者なので変でしたらすみません。
ありがとうございました!
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<fstream>
#include<string.h>
using namespace std;
void main () {
ofstream file;
file.open("C:\tests1.txt", ios::trunc);
char name[50];
cout<<"\nEnter your name: ";
cin>>name;
file<<"Username: "<<name;
file.close();
cout<<"Thank you! Your name is now in the file";
ifstream file("tests1.txt");
if(file=="Username: Chinmay") {
cout<<"If else successfull\n";
} else {
cout<<"If else failed\n";
}
_getch();
}
みんな私を助けてください!!