📄 a_10_7.cpp
字号:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{ fstream file("hello.txt",ios::in|ios::out|ios::app);
if(!file)
{ cerr << "文件打开失败"<<endl;
exit(-1);
}
int count =0;
char ch;
file.seekg(0);
while(file.get(ch))
{ cout << ch;
if ((ch=='\n')||(ch==' '))
++count;
}
if (ch!='\n') ++count;
file.clear();
file <<endl<< "共有单词"<<count<<"个";
file.close();
cin.get(); //等待结束,以便调测程序,可以删除
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -