Computing.Net > Forums > Programming > How to use string array in C++?

How to use string array in C++?

Reply to Message Icon

Original Message
Name: bctps55
Date: February 9, 2004 at 08:02:53 Pacific
Subject: How to use string array in C++?
OS: Windows XP Pro
CPU/Ram: 2Ghz/256DDR
Comment:

Hi, I don't know how to do the following because I don't know how to use the string array in C++. Please Help!!! Thanx!

#include <iostream.h>
#include <string.h>

class pizza
{
private:
char** topping;

public:
pizza(int cho);
display(int cho);
}

pizza::pizza(int cho)
{
for(int i=0; i<cho; i++)
{
topping[i][] = new char[strlen(top[i][])+1];
strcpy(topping[i][], temp[i][]);
}
}

pizza::display(int cho)
{
for(int i=0; i!=cho; i++)
for(int j=0; topping[i][j]!='\0'; j++)
cout<<topping[i][j]<<" ";
}

void main();
{
char** top={top("Ham"), top("Pineapple"), top("Onion"), top("Meatball")};
char** temp;
int num;
int choice;

count<<"Enter Number of topping: ";
cin>>num;
cout<<"\n1. Ham\n2. Pineapple\n3. Onion\n4.Meatball\n\n\nEnter num: ";
for(int i=0; i<num; i++)
{
cin>>choice;
for(int j=0; top[choice][j]!='\0'; j++)
temp[i][j]=top[choice][j];
}
temp.pizza(choice);
display(choice);
}


Report Offensive Message For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: How to use string array in C++?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software