如何从多个向量数组制作CSV文件? [英] How to make CSV file from multiple vector arrays?

查看:58
本文介绍了如何从多个向量数组制作CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vector <string> CSVWrites;
vector <string> s1; s1[0]="A";
vector <string> s2; s2[0]="B";
vector <string> s3; s3[0]="C";
vector <string> s4; s4[0]="D";

stringstream ss;
ss << s1[0].c_str()<<","<<s2[0].c_str()<<","<<s3[0].c_str()<<","<<s4[0].c_str();

CSVWrites.push_back(ss.str());





我不知道处理这种情况的更好方法,如果有一个向量,则创建CSV文件非常容易.我有100个向量,如果按照上述方式操作,我不确定stringstream是否支持那么多.
示例每个向量数组中的两个元素
A,B,C,D
E,F,G,H
.......
.......
如果您有想法,我将非常感谢您的帮助.



I don''t know the better way to handle this case, if there is one vector, it is very easy to create an CSV file. I have 100 vectors, I am not sure stringstream supports that much if I do as above way.
Example two elements from each vector array
A,B,C,D
E,F,G,H
.......
.......
If you have an idea, I am greatly appreciate for your help.

推荐答案

您可以使用std :: vector< std :: vector< std :: string>> ;表示字符串的行数组和向量迭代器,以在向量之间循环,并在内部循环中添加逗号分隔符和内部循环以及行分隔符.
就这样.
我将保留其编码,以进行简单的编码练习:-).

—SA
You can use std::vector<std::vector<std::string>> to represent array of lines of strings and vector iterator to loop through vectors adding comma separators and inner loop and line separators in outer loop.

That''s it.
I''ll leave the coding of it for a simple coding exercise :-).

—SA


这篇关于如何从多个向量数组制作CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆