Advertisement
Guest User

6.

a guest
Dec 6th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. ifstream f1;
  6. char c;
  7. int numchars, numlines;
  8.  
  9. f1.open("Test.txt");
  10.  
  11. numchars = 0;
  12. numlines = 0;
  13. f1.get(c);
  14. while (f1) {
  15. while (f1 && c == '\n') {
  16. numchars = numchars - 1;
  17. f1.get(c);
  18. }
  19. numlines = numlines + 1;
  20. f1.get(c);
  21. }
  22. cout << "The file has " << numlines << " lines and "
  23. << numchars << " characters" << endl;
  24. return(0);
  25. }
  26.  
  27. OUTPUT:
  28. The file has 202 lines and 11156 characters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement