以宽字符形式读整个文件的内容(wifstream的使用)

mac2022-06-30  29

// TestShlwAPI.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>using std::wcout;using std::endl;#include <string>using std::wstring;#include <fstream>using std::wifstream;int _tmain(int argc, _TCHAR* argv[]){       //main.cpp://读我自己    wifstream fin("TestShlwAPI.cpp");    wstring str;    wchar_t wcharArr[1024];    while (!fin.eof())    {        /*fin >> str;        wcout << str << endl;*/        fin.getline(wcharArr,1024);        wcout << wcharArr << endl;    }            while (!fin.eof())    {        fin >> wcharArr;        wcout << wcharArr << endl;    }            fin.seekg(-1);//设置读的位置影响fin.rdbuf(),不影响fin.eof()    if (!fin.bad())    {        // Dump the contents of the file to cout.        wcout << fin.rdbuf();        fin.close();    }    fin.close();    system("pause");    return 0;}

转载于:https://www.cnblogs.com/shenchao/p/3193368.html

最新回复(0)