Dear alls
I am a extremely new hand of c++ user.
Thus, I wish I can get some help in here.
I am writing a program to input a name and save in a file.
However, my problem is I want to write a function to find the worlds and show it inside the file.
For example:
I input some data like Peter, May and Joe.
Then after write and read, when the user input Peter and run the function find(), it can search the file and show Peter if Peter is existed, else run the function setuser() and let the user input the name.
My problem is I do not know how to write the function find() by using if else.....
Thank you for all the attentions!
Here is my program:
I am a extremely new hand of c++ user.
Thus, I wish I can get some help in here.
I am writing a program to input a name and save in a file.
However, my problem is I want to write a function to find the worlds and show it inside the file.
For example:
I input some data like Peter, May and Joe.
Then after write and read, when the user input Peter and run the function find(), it can search the file and show Peter if Peter is existed, else run the function setuser() and let the user input the name.
My problem is I do not know how to write the function find() by using if else.....
Thank you for all the attentions!
Here is my program:
Code:
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
char inputusername[99];// let the user to input the user name
void find();
void setuser() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
}
void read() //read the file and show the details
{
cout<<endl;
ifstream fin("file.cpp");
char ch;
while (fin.get(ch))
cout<<ch;
fin.close();
}
void write() //read the input to the file
{
ofstream fout ("file.cpp",ios::app);
fout<<inputusername<<endl;
fout.close();
}
void find()// find the input either is match the file
// if yes, cout the data
// if not, run the function setuser()
{
ifstream fin("file.cpp");
char *search;
}
int main()
{
int choice=0, number=0;
bool entered=false;
do {
cout <<endl;
cout << "Please choose an option below:\n\n";
cout << "1. input\n";
cout << "2. write\n";
cout << "3. read\n";
cout << "4. find\n";
cout << "5. Quit\n";
cin >> choice;
switch(choice) {
case (1) : { setuser();break;}
case (2) : {write(); break; }
case (3) : { read(); break; }
case (4) : { find(); break; }
case (5) : { break; }
}
}
while(choice != 5);
return 0;
}
Last edited by a moderator: