注册 登录
编程论坛 C++教室

utf-8文件流的seekg(--)

kyfi 发布于 2016-04-18 22:49, 3591 次点击
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
    string s;
    char c;
    ifstream fin("2.htm");//这是一个utf-8编码的htm文件
    if (fin.fail())
    {
        cout << "alsdj";
        exit(0);
    }
    cout<<fin.get();
    //fin.seekg(-1, ios::cur);  //没有这一步运行正常,加上这一步后,之后get()到的都是255.
    for (int i = 0; i < 10; i++)
    {
        c = fin.get();
        cout << c;
    }

}
0 回复
1