如何将.CSV excel文件的内容读入对象向量中。 [英] How do I read the contents of a .CSV excel file into into a vector of objects.

查看:140
本文介绍了如何将.CSV excel文件的内容读入对象向量中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要帮助阅读此 .csv文件的内容进入一个对象的矢量数组。我的意思是我如何阅读每个单独的字段示例:



(GIFT-01 Fresch Foundation(703)555-0054 Lopez T-Shirts Clothing 25)



进入下面main()中创建的特定向量对象,而不显示逗号。我需要这个,因为我必须为函数排序这些字段。



对于那些可能对项目的整个要求感兴趣的人, 这里 你去



我尝试过:



  / *   
Nana Amponsah
2016年11月14日。
编程项目3
UCRFClassMain.cpp - > United Cause Relief Agency类Main / Client Program.cpp(源代码)
此文件包含演示文件I / O
技术所需的源代码以及向量和对象数组
以及通过基于用户输入的六个选项之一对所述向量进行排序
* /


#include UCRF.h
#include< vector>
#include< sstream>
#include< string>
使用 命名空间标准;

int main()
{
char userChoice; // 菜单输入
string strFileName; // 文件名

vector< string> GID; // 持有礼品ID的矢量
vector< string> DNAME; // 持有捐赠者姓名的矢量
vector< string>电话; // 持有电话号码的矢量
vector< string> POC; // 矢量保持联系人
vector< string>项目; // 向量持有项目捐赠
vector< string>类别; // 向量持有捐赠项目的类型
vector< int>量; // 向量持有捐赠物品的数量

ifstream inFile; // 输入文件
ofstream outFile; // Outut文件


}





文件夹 包含所有必要的文件,如类定义,函数原型等。

解决方案

参见阅读csv c - Google搜索 [ ^ ]有关解析csv文件的建议。由于你的问题不完整,我不确定你要对所有这些向量做什么。


我会使用 struct (说)保留一行的所有字段,然后只填写一个向量< Line>

Hello I am in need of help in reading the contents of this .csv file into a vector array of objects. What i mean is how do I read each individual field example:

(GIFT-01 Fresch Foundation (703) 555-0054 Lopez T-Shirts Clothing 25)

into the specific vector objects created below in the main() without the commas showing up. I need this because I have to sort these fields for a function.

For those who may be interested in the project entire requirements, here you go

What I have tried:

/*
Nana Amponsah
November 14, 2016.
Programming Project 3
UCRFClassMain.cpp -> United Cause Relief Agency Class Main/Client Program.cpp (source code)
This file entails the source codes required to demonstrate file I/O 
techniques with vectors and making arrays of objects
As well sort said vectors via one of six options based on user input
*/

#include "UCRF.h"
#include <vector>
#include <sstream>
#include <string>
using namespace std;

int main()
{
	char userChoice;				// Menu input
	string strFileName;				// File name

	vector<string> GID;				// Vector holding Gift ID
	vector<string> DName;			// Vector holding Donor Name
	vector<string> Phone;			// Vector holding Phone Number
	vector<string> POC;				// Vector holding point of contact
	vector<string> Item;			// Vector holding item donated 
	vector<string> Category;		// Vector holding type of item donated
	vector<int> amount;				// Vector holding amount of donated items

	ifstream inFile;				// Input file
	ofstream outFile;				// Outut file


}



This folder contains all the necessary files like the class definitions, function prototypes etc.

解决方案

See read csv c - Google Search[^] for suggestions on parsing csv files. I am not sure what you are trying to do with all those vectors as your question is incomplete.


I would use a struct (say Line) holding all the fields of a line, and then fill just a single vector<Line>.


这篇关于如何将.CSV excel文件的内容读入对象向量中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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