Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                                                                                            
                
        
我想将这些字符串向量存储为4维向量。我已经搜索了三天,我无法决定是否使用多维向量,增强多数组,结构数组,...
我对cpp还是那么陌生,他们是如此混乱。

vector < string >ID;
vector < string > firstName;
vector < string > lastName;
vector < string > address;
vector<vector<vector<vector<string> >>> person ;


我该怎么办?

最佳答案

在您的情况下,创建多维数组毫无意义。我宁愿尝试:

class Person
{
public:
    string Id;
    string firstName;
    string lastName;
    string address;
};

(...)

vector<Person> People;

// Adding
Person p;
p.Id = "1234";
People.push_back(p);

// Count
std::cout << "Currently you have " << People.size() << " people in the database";

// Access
Person p1 = People[0];




编辑:回应评论

没有有关您的问题的详细信息,很难回答这个问题。据我所知,我可能会进入多类版本:

class Id
{
public:
    int Value;
    std::vector<FirstName> Names;
}

class FirstName
{
public:
    string Value;
    std::vector<SecondName> SecondNames;
}

class SecondName
{
public:
    string Value;
    std::vector<Address> Addresses;
}

class Address
{
public:
    string Value;
}

关于c++ - C++多维 vector ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20238426/

10-10 16:31