having many value in 1 variable

im doing this log-in system..

how can possibly username variable has contains many value?
Im not sure I understand

How can a char username; contain many values?
Do you mean structs?
1
2
3
4
5
struct user
{
    string username;
    string password;
};
string many_values;
User name can be inputted then validation would need to gathered. The getLine(cin, myString) function can populate the string with a full name.
Use an array?
hey packetpirate, are you familiar with arrays? i'm having trouble with mine.. do you mind stepping over to my thread and helping me out? :OO http://www.cplusplus.com/forum/beginner/63971/
what im trying to do is..

username: me

would you like to add username? (y-yes): y

add username:

username: <new username>

now you have 2 username.
Yep, make an array of strings.

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
int main()
{
  string username;
  string storedNames[100];
  int NumNames = 0;
  
  while (true)
  {
    cout << "username: ";
    getline(cin,username);
   
    bool exists = false;
    for (int i = 0; i < storedNames.size(); i++)
      if (storedNames[i] == username)
        exists == true;
   
    if (!exists)
    {
      char test;
      cout << "would you like to add this username? (y/n): ";
      cin >> test;
      if (test == y)
        storedNames[NumNames++] = username;
    }
    else
      cout << "You are logged in" << endl;

    cout << "There are " << NumNames << " usernames" << endl;
  }
}
Last edited on
@magadavixt

What's there to help with? They've already given you all the information you need.
.size() got an error.
Make sure to add this line to your file:
#include <string>
error C2228: left of '.size' must have class/struct/union type

still got this error
Oh I see the issue, I was in vector mode there for a second (instead of array mode)

Replace storedNames.size() with 100 (the length of our array)

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
int main()
{
  string username;
  string storedNames[100];
  int NumNames = 0;
  
  while (true)
  {
    cout << "username: ";
    getline(cin,username);
   
    bool exists = false;
    for (int i = 0; i < 100; i++)
      if (storedNames[i] == username)
        exists == true;
   
    if (!exists)
    {
      char test;
      cout << "would you like to add this username? (y/n): ";
      cin >> test;
      if (test == y)
        storedNames[NumNames++] = username;
    }
    else
      cout << "You are logged in" << endl;

    cout << "There are " << NumNames << " usernames" << endl;
  }
}
Topic archived. No new replies allowed.