Hi, this is my first time writing a question but I'm usally get my answer from the fourms.
I have a big project to do. one of the requiremnt is to use the array for two things and below some explain...
ID, First Name, Last Name, and numbers
123, Cathy, Ryan, 1 99 2 88 3 77 4 66 5 11 6 44 7 33 0....

so there was an ID, first , last and 1,2,3,4,5,6,7 were for the sale number and 99,88,77,66,11,44,33 were for the amount

the question is how I can divide the array above to use it for two things?

Or is any better way to do it than array>

thanks

I think I would use a vector of structures. You need two structures

struct numbers
{
    int saleNumber;
    float amount;
};

struct person
{
    int ID;
    string lastName;
    string firstName;
    vector<numbers> numberList;
};

Now just make a vector of the above person structor, e.g. vector<person> personList

I think I would use a vector of structures. You need two structures

struct numbers
{
    int saleNumber;
    float amount;
};

struct person
{
    int ID;
    string lastName;
    string firstName;
    vector<numbers> numberList;
};

Now just make a vector of the above person structor, e.g. vector<person> personList

thanks Ancient Dragon,
but i'm not allow to use vector in my prog. Do you think in something else please ?
thanks again.

You said: >>Or is any better way to do it than array>
I answered that question.

>>Do you think in something else please ?
Replace the vector with linked list or replace it with a c-style array of those structures

Sorry. do you think I can divide the array
thanks.

If by "divide the array" you mean split each line up into its individual parts, then Yes that can be easily done. The c++ stringstream class will help do that. This will NOT work if there are no spaces after the commas.

#include <sstream>
#include <string>
#include <iostream>

int main()
{
     string line = "123, Cathy, Ryan, 1 99 2 88 3 77 4 66 5 11 6 44 7 33 0";
     string word;
     stringstream stream(line);
     while(stream >> word)
     {
         // got a word from the line.  Now do something with it.
     }
}

thank you. hurray this is work well

Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.