#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int cnt = 0;
FILE *fp=fopen("stdin", "r");
FILE *fout = fopen("stdout", "w");
fseek(fp, 0, SEEK_END);
int filesize = ftell(fp);
fseek(fp, 0, SEEK_SET);
char* buf = new char[filesize + 1];
int n = fread(buf, 1, filesize, fp);
if (n > 0)
buf[n] = 0;
for (int i = 0; i < n; i++)
{
if (buf[i] == '$')
cnt++;
}
char s[1024];
memset(s, '\0', sizeof(s));
sprintf(s, "%d", cnt);
fwrite(s, 1,sizeof(s), fout);
delete[]buf;
fclose(fp);
fclose(fout);
//system("pause");
return 0;
}
c++读取文件内容并统计指定字符的个数
最新推荐文章于 2024-03-12 12:08:54 发布