Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:

C#
/*
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.
Posted
Updated 15-Nov-16 23:30pm
Comments
[no name] 15-Nov-16 13:32pm    
In C++ it's called "tokenize" or you can parse the line yourself.

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.
 
Share this answer
 
I would use a struct (say Line) holding all the fields of a line, and then fill just a single vector<Line>.
 
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