By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,654 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

Variation on counting lines in a text file

P: 5
Hi,

I want to count lines in a text file in the format below:

255.000000,148.000000,0.000000,0.000000
255.000000,229.000000,0.000000,0.000000
255.000000,215.000000,0.000000,0.000000

37.000000,0.000000,0.000000,0.000000
71.000000,0.000000,0.000000,50.000000
97.000000,15.000000,0.000000,0.000000

37.000000,0.000000,0.000000,0.000000
71.000000,0.000000,0.000000,50.000000
97.000000,15.000000,0.000000,0.000000

I need to count the amount of lines in each cluster of data above - so in this example, I need to return 3,3,3.

I can count the lines in the entire file using:

Expand|Select|Wrap|Line Numbers
  1. return static_cast<int>( std::count( std::istreambuf_iterator<char>(In),std::istreambuf_iterator<char>(), '\n' ) );
  2.  
But, I've no clue how to go about doing what I need to do above. Any idea's would be really appreciated...I've been trying to figure this out for a while now and am getting nowhere fast!

I'm using Visual Studio 2003 on Windows XP.
Mar 21 '07 #1
Share this Question
Share on Google+
7 Replies


RedSon
Expert 5K+
P: 5,000
The reason no one is answering your question is because it has been asked a thousand times before. Try searching this site or google.
Mar 21 '07 #2

P: 5
I have looked...but I'll try again
Mar 21 '07 #3

P: 5
thanks...I've seen most of these. I'll go over them again to see if I gain any new insights, but my problem is slightly different. I already know how to count the lines in the entire file.
Mar 21 '07 #5

P: 5
A colleague to the rescue...the solution is always so simple when you finally see it.

Expand|Select|Wrap|Line Numbers
  1. *snipped per homework policy*
  2.  
Mar 21 '07 #6

P: 5
Out of curiosity, was that removed because you think it's my homework or to stop other students using it? (just so I know for future reference...)
Mar 21 '07 #7

RedSon
Expert 5K+
P: 5,000
Other students from using it.
Mar 21 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.