C++ help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2006
Posts: 7
Reputation: robase is an unknown quantity at this point 
Solved Threads: 0
robase robase is offline Offline
Newbie Poster

C++ help

 
0
  #1
May 13th, 2006
I need some help to do the following
Count all spaces written to the output file
Count all alphabetic characters in the output file

  1. include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9. string line;
  10. ifstream myfile ("checkIn.dat");
  11. if (myfile.is_open())
  12. {
  13. while (! myfile.eof() )
  14. {
  15. getline (myfile,line);
  16. cout << line << endl;
  17. }
  18. myfile.close();
  19. }
  20.  
  21. else cout << "Unable to open file";
  22.  
  23. return 0;
  24. }
Last edited by cscgal; May 14th, 2006 at 12:56 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 54
Reputation: HackWizz is an unknown quantity at this point 
Solved Threads: 2
HackWizz HackWizz is offline Offline
Junior Poster in Training

Re: C++ help

 
0
  #2
May 14th, 2006
Originally Posted by robase
I need some help to do the following
Count all spaces written to the output file
Count all alphabetic characters in the output file

  1. include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9. string line;
  10. ifstream myfile ("checkIn.dat");
  11. if (myfile.is_open())
  12. {
  13. while (! myfile.eof() )
  14. {
  15. getline (myfile,line);
  16. cout << line << endl;
  17. }
  18. myfile.close();
  19. }
  20.  
  21. else cout << "Unable to open file";
  22.  
  23. return 0;
  24. }
You can include ctype.h and it has functions isspace and isalpha which will help you ...and you need to extract character by character.
return 0;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC