剛從C#開始轉C++,有很多東西不理解,如下邊這段代碼:
#include
#include
int main() {
using namespace std;
ifstream file;
basic_ifstream
char c;
// Open and close with a basic_filebuf
file.rdbuf()->open( "basic_filebuf_close.txt", ios::in );
file >> c;
cout << c << endl;
file.rdbuf( )->close( );
// Open/close directly
file.open( "iotest.txt" );
file >> c;
cout << c << endl;
file.close( );
// open a file with a wide character name
wfile.open( L"iotest.txt" );
// Open and close a nonexistent with a basic_filebuf
file.rdbuf()->open( "ziotest.txt", ios::in );
cout << file.fail() << endl;
file.rdbuf( )->close( );
// Open/close directly
file.open( "ziotest.txt" );
cout << file.fail() << endl;
file.close( );
}
下邊是我跟大牛的聊天記錄,疑問解開。(有個大牛幫解答疑問感覺就是爽啊!)