L
Lambda
I'd like to load a text file to memory. The code is like:
void load_dict()
{
static const string DICT("D:\\README.txt");
ifstream dict(DICT.c_str(), std::ios::in);
if (!dict)
{
cerr << "can't open input file: " << DICT << endl;
}
vector<unsigned char> raw;
char c;
while (dict.get(c))
{
raw.push_back(c);
}
cout << raw.size() << endl;
}
It says there is 36388 bytes. That's correct.
But if I change the code to 'dict >> c', there is only 29658 bytes.
What's wrong with the >> operator?
I'm developing under Windows to read unix format file.
And if I change the code to:
unsigned char c;
while (dict.get(c)) ...
There is compilation errors.
What can I do if I want to load binary data?
void load_dict()
{
static const string DICT("D:\\README.txt");
ifstream dict(DICT.c_str(), std::ios::in);
if (!dict)
{
cerr << "can't open input file: " << DICT << endl;
}
vector<unsigned char> raw;
char c;
while (dict.get(c))
{
raw.push_back(c);
}
cout << raw.size() << endl;
}
It says there is 36388 bytes. That's correct.
But if I change the code to 'dict >> c', there is only 29658 bytes.
What's wrong with the >> operator?
I'm developing under Windows to read unix format file.
And if I change the code to:
unsigned char c;
while (dict.get(c)) ...
There is compilation errors.
What can I do if I want to load binary data?