fopen_s 从文件读取字符串


#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); }

 

posted @ 2019-06-12 09:24  大芝麻  阅读(1498)  评论(0编辑  收藏  举报