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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to use string array in C++?

Reply to Message Icon

Name: bctps55
Date: February 9, 2004 at 08:02:53 Pacific
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);
}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How to use string array in C++?

how to use Dos commands in Borlad C www.computing.net/answers/programming/how-to-use-dos-commands-in-borlad-c/4175.html

How to use Switch statement in vb www.computing.net/answers/programming/how-to-use-switch-statement-in-vb/6687.html

System-pause - in c#? www.computing.net/answers/programming/systempause-in-c/10626.html