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

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM