第16周實踐項目1(1)——小玩文件

/*
*Copyright (c) 2016,煙臺大學計算機學院
*All rights reserved.
*文件名稱 :
*作 者 : 劉雲
*完成日期 : 2016年6月15號
*版 本 號 : v6.0
*
*問題描述 : 實踐項目
*輸入描述 :無
*程序輸出 :
*/
#include <iostream>
#include <cstdlib>
#include <fstream> // (1)
using namespace std;
int main()
{
    fstream file;
    file.open("abc.txt", ios::in); // (2)
if(!file)
{
        cout<<"abc.txt can’t open."<<endl;
        exit(1);
    }
    char ch;
    int i=0;
    while(file.get(ch)) // (3)
    {
        ++i; // (4)
    }
    cout<<"Character: "<<i<<endl;
    file.close();// (5)
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章