函数原型:
istream& getline ( istream& is, string& str, char delim );
istream& getline ( istream& is, string& str );
读取文件,第一个按参数delim作为分隔符,第二个以'\n'作为分隔符。
问题产生:
在windows,新建文本文档,输入字符,换行保存,另存时选择文件编码为 unicode big endian.
在用上面第二个函数读取该文本的时候,会忽略掉第一行的字符。
文本示例:(三个逗号,windows平台下另存文件,选择编码:unicode big endian)
,
,
,
程序示例
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream ifs("unicode_big_endian.txt");
string str;
int i = 0;
while(getline(ifs, str))
{
printf("%04X\n", *(unsigned short *)str.c_str());
}