Hi,
I have wrote a program which stores values in a .csv file.
He is the how the data is stored in the .csv file:
Each line forms a single object."Steve","21 Main Street, Nottingham","SW1 1AB","0115 9123456","These are some details. and, so.","112233","1359"
"David Baner","123 Shaw street, Nottingham","NG92HJ","020 123456","ifbiugbuige","112233","1200"
What I want to do is retrieve the values from the .csv file, so that I can recreate the objects again, but after reading Google, find myself a little lost in how go about this as simply as possible.
So i was thinking of something like this:
What datatype should I use for storing the line? ie: the 'storelinevariable' parameter?Code:cout << "You chose to load from the CSV file" << endl; ofstream streamname("database.csv"); if(!streamname) { cout << "Cannot open file" << endl; return 1; } else { cout << "Stream opened successfully" << endl; } getline( streamname, storelinevariable, '\n' );
I use the following function for adding the double quotes to the datamember values when constructing an object:
But once a line is retrieved, this is an example of how I would like to construct the object:Code://Virtual function for adding double quotes to strings input by the user for use in the .csv file: virtual void addDoubleQuotes(string& m_Name,string& m_Address,string& m_PostCode,string& m_TelNo,string& m_Details) { m_Name = '\"' + m_Name + '\"'; m_Address = '\"' + m_Address + '\"'; m_PostCode = '\"' + m_PostCode + '\"'; m_TelNo = '\"' + m_TelNo + '\"'; m_Details = '\"' + m_Details + '\"'; }
Code:Derived *ptr = new Derived(mainname, mainaddress, mainpostcode, maintelno, maindetails, maindate, maintime); vectorname.push_back( ptr );
So if anyone could point me in the right direction, I'd really appreciate it!
Many thanks!



LinkBack URL
About LinkBacks



