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

论坛 期权论坛 脚本     
匿名技术用户   2021-1-4 12:39   52   0

// 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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP