| | |
reading, modifying data within .csv file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 35
Reputation:
Solved Threads: 0
Hi all,
Good day to all.
I trying to do a program using VC++ window form that involved loading the data from .csv file and displayed it into the window form with labels. Vice versa, when the user key in data, four of the below show column values will changed, i can made the values changes accordingly within the form.
However, i do not know how to do the saving of the data back to csv or load the data from csv into window form.
Below shown is the sample containing the 1st row of 28 column then every row are the same with different values. And its fixed with 38 row by 28 column of data.
Lets make it simple say i want to change the value in column 6( which is 4) to 8 and column 1 (which is Name) to john, how can i do it simply if i were to do it with all 38 rows. The last three column are also a headache as they contained lot of commas and its not fixed.
Any advices, pointers will be greatly appreciated. Thanks in advance.
"Name",,"0","0",,"4","1","5",,"3","1","1","5",,"1","2","2","1","6",,"5",,"21",,"","1,2,16,20,21","7,9,13,17,18","3,6,11,12,14,15"
Good day to all.
I trying to do a program using VC++ window form that involved loading the data from .csv file and displayed it into the window form with labels. Vice versa, when the user key in data, four of the below show column values will changed, i can made the values changes accordingly within the form.
However, i do not know how to do the saving of the data back to csv or load the data from csv into window form.
Below shown is the sample containing the 1st row of 28 column then every row are the same with different values. And its fixed with 38 row by 28 column of data.
Lets make it simple say i want to change the value in column 6( which is 4) to 8 and column 1 (which is Name) to john, how can i do it simply if i were to do it with all 38 rows. The last three column are also a headache as they contained lot of commas and its not fixed.
Any advices, pointers will be greatly appreciated. Thanks in advance.
"Name",,"0","0",,"4","1","5",,"3","1","1","5",,"1","2","2","1","6",,"5",,"21",,"","1,2,16,20,21","7,9,13,17,18","3,6,11,12,14,15"
•
•
Join Date: Jun 2008
Posts: 35
Reputation:
Solved Threads: 0
•
•
•
•
To change the value you have to completely rewrite the entire file. You will have to write the file back out in the same format from the data that is in the Form.
Currently, i am doing it the entire file way thought of shortening it if possible, cause its 38 by 28 data to be rewrote. since its from you, i believed the only way is the entire way lol

How about loading it back to window form, any pointers on this?
•
•
Join Date: Jun 2008
Posts: 35
Reputation:
Solved Threads: 0
•
•
•
•
>>How about loading it back to window form, any pointers on this?
Not really, without knowing how you are doing it now.
edit: since i know which line and column the data is in within the .csv file, any idea on how to directly get to say line 6, column 8 with all those commas in the line?
Thanks in advance.
Last edited by integer*09; Jan 15th, 2009 at 4:49 am.
•
•
•
•
Now i have done with the entire writing of the 1st row, to be frank, i am not really sure how to load it back.
edit: since i know which line and column the data is in within the .csv file, any idea on how to directly get to say line 6, column 8 with all those commas in the line?
Thanks in advance.
#include <string>
#include <fstream>
#include <sstream>
...
...
std::string line;
ifstream in("file.csv");
int lineToGet = 6;
// read all lines until you get to
// the one you want
for(int i = 0; i < lineToGet; i++)
getline(in,line);
// now that we have the line we want,
// split it into columns
stringstream str(line);
std::string column;
for(int i = 0; i < 5; i++)
getline(str, column, ',');
// now, the 5th column is in variable column.
// Since its enclosed in double quotes you will
// have to strip those out before adding to your Form Last edited by Ancient Dragon; Jan 15th, 2009 at 5:59 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jun 2008
Posts: 35
Reputation:
Solved Threads: 0
I have the below code almost similar to yours but the value shown in the textbox is always "True", however if i remove the .c_str from it, i will get "error C2665: 'System::Convert::ToString' : none of the 37 overloads could convert all the argument types."
Anyone knows where it goes wrong???
Anyone knows where it goes wrong???
std::string line;
int colCnt = 0, lineCnt = 0;
ifstream in("tsing.csv",ios::binary);
while (getline(in,line,'\n'))
{
lineCnt++;
if (lineCnt==4)
{
stringstream sstr(line);
std::string coln;
getline(sstr,coln,'"');
testBox1->Text = Convert::ToString(coln.c_str());
}
}•
•
Join Date: Jun 2008
Posts: 35
Reputation:
Solved Threads: 0
•
•
•
•
why do you need Convert::ToStrig()? coln is already a string, just send it to testBox1->Text.
error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'std::string' to 'System::String ^'
Last edited by Ancient Dragon; Jan 15th, 2009 at 11:17 pm. Reason: disable smilies in text
Oh, I see you are using c++ managed code. You will have to convert char* to System::String -- I don't know how to do that because I've never written managed code. Someone else will have to help you, or you can look it up in your text book, or google for it.
Last edited by Ancient Dragon; Jan 15th, 2009 at 11:19 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Other Threads in the C++ Forum
- Previous Thread: creating and searching multi array
- Next Thread: help needed in biomatrix
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






