comparing string in file

Well forgive me for the possibly obvious question. It's been 3 years since i've progammed in c++ :P

Anyways I'm trying to compare a string from a file to a string inputed to from a user. If the string doesnt match to any of the file, i want it to write it to the file. The writing part is working, the comparing? not so much.... It's a basic log in prompt.
(and no the problem isnt in the header)
...two of those headers I included from habit...
heres the code
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "users.h" //user class
#include <cstdio> 
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;
//================Global Variables==========//
user current_user;
user new_user;
ofstream users;
ifstream usersin;

//================Erike menu===============//
int menu(void)
{
    //TODO: Menu Code (learn, play, work)
}
//===============return user===============//
int return_user(void)
{
    cout << "Welcome ";
    cout << current_user.fname;
    menu();
}
//==============New User===================//
int new_users(void)
{
    users.open("users.ini", ios::app);

    new_user.fname = current_user.fname;
    users << "new_user: \n";
    users << current_user.fname;
    users << "\n";
    menu();
}
//==============Welcome screen=============//
int welcome(void)
{
   string userlist[16];
   usersin.open("users.ini", ios::in); //open users.ini for background check
    
   cout << "Hiya! My name is Erika, who are you?";
   cin >> current_user.fname;
   for(int J = 1; J <= 16; J++)
   {
   getline(usersin, userlist[J]);
   }

   if (userlist[2] == current_user.fname) //check for return user
      {
           return_user();
      } else if (current_user.fname == userlist[4])
      {
           return_user();
      } else if (current_user.fname == userlist[6])
      {
             return_user();
      } else if (current_user.fname == userlist[8])
      {
             return_user();
      } else if (current_user.fname == userlist[10])
      {
             return_user();
      } else if (current_user.fname == userlist[12])
      {
             return_user();
      } else { new_users(); }
             
      usersin.close();
             
}
//==============Main=====================//
int main(int nNumberofArgs, char* szArs[])
{
    welcome();
        system("PAUSE");
    return 0;
}




Id like to point out that I'm rather new to object oriented programming, I've only studied it a little and that was 3 years ago....
Last edited on
what kind of file is this and what kind of matching you want to do? is it a whole line matching or word matching in file??
can you give an example for this?
while its an INI right now, though I havent formatted in the input like it is.
and it is whole line matching. Although I now know how to make it word matching

For an example?

Say Your a new user? Type in your name, I dont know, Alex? If that name is in the file, I want it to go to the return user function and execute that code, if not, I want it to create a new user.

does that help?
Topic archived. No new replies allowed.