#include<iostream>
#include<fstream>
#include<string>
int main()
{
using namespace std;
string filename = "text.txt";
ifstream inFile;
int i = 0;
char ch;
inFile.open(filename);
if (!inFile.is_open())
{
cout << "打开文件失败" << endl;
exit(EXIT_FAILURE);
}
while (!inFile.eof())
{
ch = inFile.get();
++i;
cout << ch;
}
cout << "共有" << i << "个字符";
inFile.close();
cin.get();
cin.get();
system("pause");
return 0;
#include<fstream>
#include<string>
int main()
{
using namespace std;
string filename = "text.txt";
ifstream inFile;
int i = 0;
char ch;
inFile.open(filename);
if (!inFile.is_open())
{
cout << "打开文件失败" << endl;
exit(EXIT_FAILURE);
}
while (!inFile.eof())
{
ch = inFile.get();
++i;
cout << ch;
}
cout << "共有" << i << "个字符";
inFile.close();
cin.get();
cin.get();
system("pause");
return 0;
}