| | |
How to read data from csv file in an array and parse
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
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"
Views: 22586 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






