Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i make std:string items from single string to array of strings , and how can i define it ?

What I have tried:

C++
#ifndef ORDER_H
#define ORDER_H
#include <string>

class order
{
private:
    int OrderNum;
    std::string items;
    std::string orderDate;
    int customerId;
    std::string paymentMethod;
    bool approved;

public:
    order();
    order(int orNum,std::string itms, std::string orDate, int cuId, std::string pay, bool approve);
    ~order();

};

#endif // ORDER_H
Posted
Updated 28-Dec-16 6:13am
Comments
CPallini 28-Dec-16 15:57pm    
You question is not clear. Could please detail your scenario?

1 solution

If you want a fixed size array - declare the member as an array.

C++
std::string items[100];

items[0] = "zero";
items[1] = "one";
items[2] = "two";


If the length must be variable, use a vector.

vector - C++ Reference[^]

C++
#include <vector>

std::vector<std::string> items;

items.push_back("zero");
items.push_back("one");
items.push_back("two");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900