How to read data from csv file in an array and parse

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: How to read data from csv file in an array and parse

 
0
  #11
Jul 14th, 2006
If I showed you how to tokenise a string rather than a char array would that be ok?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: How to read data from csv file in an array and parse

 
0
  #12
Jul 14th, 2006
>> 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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: How to read data from csv file in an array and parse

 
0
  #13
Jul 14th, 2006
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!
he/she prolly doesn't even know what a class is.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 10
Reputation: rdubey_jsr is an unknown quantity at this point 
Solved Threads: 0
rdubey_jsr rdubey_jsr is offline Offline
Newbie Poster

Re: How to read data from csv file in an array and parse

 
0
  #14
Jul 14th, 2006
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!
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: How to read data from csv file in an array and parse

 
0
  #15
Jul 14th, 2006
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:
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. string tmp = "What,the,hell,are,you,say,in,mo,fo";
  12.  
  13. vector <string> array;
  14.  
  15.  
  16. string token;
  17. istringstream iss(tmp);
  18. while ( getline(iss, token, ',') )
  19. {
  20. array.push_back(token);
  21. cout << token <<endl;
  22. }
  23.  
  24. cin.get();
  25. }

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*
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: How to read data from csv file in an array and parse

 
0
  #16
Jul 14th, 2006
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.
In that case, you need to ease off on your project and do something closer to your current skill level. If you can't figure out how to use such a simple class, you're not even close to being ready to parse CSV files and write MFC apps.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 10
Reputation: rdubey_jsr is an unknown quantity at this point 
Solved Threads: 0
rdubey_jsr rdubey_jsr is offline Offline
Newbie Poster

Re: How to read data from csv file in an array and parse

 
0
  #17
Jul 15th, 2006
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:
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. string tmp = "What,the,hell,are,you,say,in,mo,fo";
  12.  
  13. vector <string> array;
  14.  
  15.  
  16. string token;
  17. istringstream iss(tmp);
  18. while ( getline(iss, token, ',') )
  19. {
  20. array.push_back(token);
  21. cout << token <<endl;
  22. }
  23.  
  24. cin.get();
  25. }

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........
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 22586 | Replies: 16
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC