943,901 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 37240
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 14th, 2006
0

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

If I showed you how to tokenise a string rather than a char array would that be ok?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 14th, 2006
0

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

>> 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!
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
Jul 14th, 2006
0

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

Quote 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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 14th, 2006
0

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

Quote 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rdubey_jsr is offline Offline
10 posts
since Jul 2006
Jul 14th, 2006
0

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

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)
  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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 14th, 2006
0

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

Quote ...
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.
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
Jul 15th, 2006
0

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

Quote 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)
  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........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rdubey_jsr is offline Offline
10 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Dynamically Add Event Handler without using this pointer
Next Thread in C++ Forum Timeline: another "segmentation fault"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC