I've been doing some basic file manipulations with iostreams in Visual Studio 2015 and noticed this weird behavior.
#include <fstream>
#include <iostream>
#include <sstream>
void main(int argc, char** argv)
{
std::wifstream stream("example.txt");
//std::ifstream stream("example.txt");
//std::wstringstream stream(L"abcdefghijklmnopqrstuvxyz");
std::wcout << (char)stream.peek() << "\n"; // a
stream.tellg();
std::wcout << (char)stream.peek() << "\n"; // b
stream.tellg();
std::wcout << (char)stream.peek() << "\n"; // c
stream.tellg();
std::wcout << (char)stream.peek() << "\n"; // d
stream.tellg();
std::wcout << (char)stream.peek() << "\n"; // e
stream.tellg();
std::wcout << (char)stream.peek() << "\n"; // f
stream.tellg();
std::wcout << (char)stream.peek() << "\n"; // g
stream.tellg();
}
example.txt contains:
abcdefghijklmnopqrstuvxyz
It seems like stream.tellg()
advances the stream's current character by one. This happens only for std::wifstream
. std::ifstream
and std::wstringstream
seem not to be affected.
Is this a bug in visual studio stl implementation?