您的位置:首页 > 其它

vector<vector<string>> 双层vector使用

2015-11-17 17:06 525 查看
vector<vector<string>> 双层vector使用

当我在读写数据库时,数据库数据保存的问题是个难点,而我考虑的是双层vector数据结构来存储数据。

std::vector<std::vector<std::string>>& vAllRow

while(读取数据到r中)

{

std::vector<std::string> vRow;

vRow.clear();

vRow.push_back(r[0]);

vRow.push_back(r[1]);

vRow.push_back(r[2]);

vRow.push_back(r[3]);

vRow.push_back(r[4]);

vRow.push_back(r[5]);

vAllRow.push_back(vRow);

}

将数据存储在了vAllRow中,下面将读取其中的数据显示出来。

vector<vector<std::string>>::iterator item2v = vAllRow.begin();

while(item2v !=vAllRow.end())

{

vector<std::string>::iterator item = (*item2v).begin();

while(item != (*item2v).end())

{

cout<<*item<<"\t";

item++;

}

std::cout<<std::endl;

item2v++;

}

将数据保存在vector中容易操作,以上代码可使数据显示在终端。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: