| | |
How to read data from csv file in an array and parse
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
•
•
Originally Posted by Dogtree
>> can u give send me some code how to seperate the contents from commas.
That nice convenient class I posted that does exactly what you asked for must not have been what you really wanted. Why are you using char arrays anyway? How archaic!
*Voted best profile in the world*
•
•
Join Date: Jul 2006
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dogtree
>> can u give send me some code how to seperate the contents from commas.
That nice convenient class I posted that does exactly what you asked for must not have been what you really wanted. Why are you using char arrays anyway? How archaic!
There's no point worrying about classes here. It will prolly just confuse you. Especially if you had to ask how it may be used with main. And don't forget, you have to incorporate this into an MFC application! Things could get ugly if you don't know what you're doing.
So here's a simple example:
If you're dead set on using char arrays this may also be of use:-
http://faq.cprogramming.com/cgi-bin/...&id=1044780608
So here's a simple example:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; int main() { string tmp = "What,the,hell,are,you,say,in,mo,fo"; vector <string> array; string token; istringstream iss(tmp); while ( getline(iss, token, ',') ) { array.push_back(token); cout << token <<endl; } cin.get(); }
If you're dead set on using char arrays this may also be of use:-
http://faq.cprogramming.com/cgi-bin/...&id=1044780608
Last edited by iamthwee; Jul 14th, 2006 at 2:04 pm.
*Voted best profile in the world*
•
•
•
•
Yes, you have posted a good class but can u give main() function code also, how to call the class and which member function. Means how to read the file (.CSV) and pass in the object of class and get the parsed content as output.
•
•
Join Date: Jul 2006
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by iamthwee
There's no point worrying about classes here. It will prolly just confuse you. Especially if you had to ask how it may be used with main. And don't forget, you have to incorporate this into an MFC application! Things could get ugly if you don't know what you're doing.
So here's a simple example:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; int main() { string tmp = "What,the,hell,are,you,say,in,mo,fo"; vector <string> array; string token; istringstream iss(tmp); while ( getline(iss, token, ',') ) { array.push_back(token); cout << token <<endl; } cin.get(); }
If you're dead set on using char arrays this may also be of use:-
http://faq.cprogramming.com/cgi-bin/...&id=1044780608
Yes, Now its working fine for me. Thanks, for solving my problem........
![]() |
Similar Threads
- read second line or record of csv file (PHP)
- Reading in certain columns from CSV files into array C++ (C++)
- parse a csv file (PLEASE HELP) (Java)
Other Threads in the C++ Forum
- Previous Thread: Dynamically Add Event Handler without using this pointer
- Next Thread: another "segmentation fault"
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






