Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- int main()
- {
- char str[80];
- int count=0;
- fstream file1;
- file1.open("C:\\text.txt",ios_base::in );
- fstream file2;
- file2.open("C:\\text2.txt",ios_base::out);
- if (!file1 || !file2)
- cout << "檔案開啟失敗" << endl;
- else
- {
- file1.getline(str,80);
- cout << str << endl;
- file2 << str << endl;
- for (int i = 0; i < 80; i++)
- {
- if (str[i] == 3)
- count++;
- }
- file1.getline(str,80);
- cout << str << endl;
- file2 << str << endl;
- for (int i = 0; i < 80; i++)
- {
- if (str[i] == 3)
- count++;
- }
- }
- cout << "3的個數有" << count << "個" << endl;
- }
Add Comment
Please, Sign In to add comment