2010-05-11 21:42:16 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-05-11 23:36:01 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
2010-11-16 23:09:02 +01:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <fstream>
|
|
|
|
|
|
|
|
// template <class charT, class traits = char_traits<charT> >
|
|
|
|
// class basic_ofstream
|
|
|
|
|
|
|
|
// void open(const string& s, ios_base::openmode mode = ios_base::out);
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2011-07-19 01:51:21 +02:00
|
|
|
char temp[L_tmpnam];
|
|
|
|
tmpnam(temp);
|
2010-05-11 21:42:16 +02:00
|
|
|
{
|
|
|
|
std::ofstream fs;
|
|
|
|
assert(!fs.is_open());
|
|
|
|
char c = 'a';
|
|
|
|
fs << c;
|
|
|
|
assert(fs.fail());
|
2011-07-19 01:51:21 +02:00
|
|
|
fs.open(std::string(temp));
|
2010-05-11 21:42:16 +02:00
|
|
|
assert(fs.is_open());
|
|
|
|
fs << c;
|
|
|
|
}
|
|
|
|
{
|
2011-07-19 01:51:21 +02:00
|
|
|
std::ifstream fs(temp);
|
2010-05-11 21:42:16 +02:00
|
|
|
char c = 0;
|
|
|
|
fs >> c;
|
|
|
|
assert(c == 'a');
|
|
|
|
}
|
2011-07-19 01:51:21 +02:00
|
|
|
remove(temp);
|
2010-05-11 21:42:16 +02:00
|
|
|
{
|
|
|
|
std::wofstream fs;
|
|
|
|
assert(!fs.is_open());
|
|
|
|
wchar_t c = L'a';
|
|
|
|
fs << c;
|
|
|
|
assert(fs.fail());
|
2011-07-19 01:51:21 +02:00
|
|
|
fs.open(std::string(temp));
|
2010-05-11 21:42:16 +02:00
|
|
|
assert(fs.is_open());
|
|
|
|
fs << c;
|
|
|
|
}
|
|
|
|
{
|
2011-07-19 01:51:21 +02:00
|
|
|
std::wifstream fs(temp);
|
2010-05-11 21:42:16 +02:00
|
|
|
wchar_t c = 0;
|
|
|
|
fs >> c;
|
|
|
|
assert(c == L'a');
|
|
|
|
}
|
2011-07-19 01:51:21 +02:00
|
|
|
remove(temp);
|
2010-05-11 21:42:16 +02:00
|
|
|
}
|