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