#include "stdafx.h" #include <fstream> #include <iostream> #include <string> #include <cstdlib> using namespace std; int main() { FILE *fp; errno_t err = fopen_s(&fp, "D://1.TXT", "rt"); //读取文件数据 cout << err << endl; char s[2]; int index = 0; while (!feof(fp)) { //fscanf_s(fp, "%c",&s);读取字符方式一 //if (fread(s, 1, 2, fp) == 0) break;读取字符串方式二,一次读取两个 index++; cout << (s[0])<<s[1]; } cout << endl; cout << index; fclose(fp); }