gha890826

期末考預告-2

Jun 10th, 2019
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. // ConsoleApplication1.cpp : 定義主控台應用程式的進入點。
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. using namespace std;
  9.  
  10. void main()
  11. {
  12.     ifstream data;
  13.     data.open("C:\\log.txt", ios::in);
  14.     if (!data)
  15.     {
  16.         cout << "Open fail\n";
  17.     }
  18.     string n;
  19.     int counter=0;
  20.     while (!data.eof())
  21.     {
  22.         data >> n;
  23.         for (int i = 0; i < n.length(); i++)
  24.         {
  25.             if (n[i] == '3')
  26.                 counter++;
  27.         }
  28.     }
  29.     cout << counter << endl;
  30. }
Add Comment
Please, Sign In to add comment