Array of strings to store data...

Good evening!

I am working on a problem where I need to use an array of strings to store email addresses. The user of the program should be able to list all the email addresses, delete an email address, search an email address and list all email addresses. I am stuck on how to enter multiple addresses into the array to that they can be worked with.

Here is what I have so far:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#include <iostream>
#include <cstring>
using namespace std;

int main ()
{
  char eAddress[80] = {};
  
  // Prompt user for an email address
  cout << "Email Address? " << endl;
  cin.getline(eAddress, 80);
  cout << eAddress << endl;
  
  system("pause");
  return 0;
}


I can get the program to accept the input from the user, store the address in the array (80 chars max) and then print it back out to the screen. How do I get the array to accept multiple addresses and store them for use? Do I use a multi-dimensional array?

Thanks!
No, you use an array of strings.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
  vector<string> addresses;
  for (;;)
  {
    cout << "Email Address? " << endl;
    string address;
    if (!getline(cin,address) || address.empty())break;
    addresses.push_back(address);
  }
}

Im new to programming but how do you store email addresses.
hm... you used C-style strings.. ie char arrays...
you'd better use C++ style strings by including <string>
also, i would prefer a vector of string rather than array...
so... the solution by Athar will help you..

if you would like to stick to C-style array, you have to use a multidimensional array..

char adresses[200][80] // to make an array containing 100 emails each of size 80
I need help in storing the email addresses below, delete them or do a search. Should I be storing them on a file on my computer to call the function. Please help!!!!!!!!!!!!!!!
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
vector<string> addresses



string str1 = "joviking@gmail.com";
string str2 = "kim1994@yahoo.com";
string str3 = "success10@verizon.net";
string str4 = "jmllove@gmail.com";
string str5 = "billsmith@yahoo.com";
string str6 = "baller4life@verizon.net";
sring str7 = "focusmoreontrips@gmail.com"
1
2
3
4
addresses.push_back("joviking@gmail.com");
addresses.push_back("kim1994@yahoo.com");
addresses.push_back("success10@verizon.net");
// ... etc ... 
Shoud my program look like this: My goal is to call the email addresses from the string to have the users to choose whether they want to list the email address which is number 3

#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> addresses;

string str1 = "joviking@gmail.com";
string str2 = "kim1994@yahoo.com";
string str3 = "success10@verizon.net";
string str4 = "jmllove@gmail.com";
string str5 = "billsmith@yahoo.com";
string str6 = "baller4life@verizon.net";
string str7 = "focusmoreontrips@gmail.com";

bool processMenu()
{
cout << "1. Enter an email address. " << endl;
cout << "2. Search for an email address. " << endl;
cout << "3. List all email addresses. " << endl;
cout << "4. Delete an email address. " << endl;
cout << "5. Exit. " << endl;

char choice;
cin >> choice;

if(choice == '1'){
cout << "You chose option #1." << endl;
cout << "Please enter the address: ";
string address;
cin>> address;
addresses.push_back(address);
processMenu();

}else if(choice == '2')
{

cout << "You chose option #2." << endl; //Add Stuff Here
processMenu();


cout << "You chose option #3." << endl;
cout << "Listing addresses. " << endl;
for(int i = 0; i << addresses.size(); i++)
{
cout << "Email Address # " << i + 1 << ": " << addresses[i] << endl;
}
processMenu();

I really think you should avoid using recursion like that (calling processMenu() from within processMenu()). It would be much better to use a while() loop instead.

Topic archived. No new replies allowed.