ctor_string_error_code.pass.cpp revision d90b0a41a8f0995602f0f7ee2541ff724079b20b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <ios> 11 12// class ios_base::failure 13 14// explicit failure(const string& msg, const error_code& ec = io_errc::stream); 15 16#include <ios> 17#include <string> 18#include <cassert> 19 20int main() 21{ 22 { 23 std::string what_arg("io test message"); 24 std::ios_base::failure se(what_arg, make_error_code(std::errc::is_a_directory)); 25 assert(se.code() == std::make_error_code(std::errc::is_a_directory)); 26 std::string what_message(se.what()); 27 assert(what_message.find(what_arg) != std::string::npos); 28 assert(what_message.find("Is a directory") != std::string::npos); 29 } 30 { 31 std::string what_arg("io test message"); 32 std::ios_base::failure se(what_arg); 33 assert(se.code() == std::make_error_code(std::io_errc::stream)); 34 std::string what_message(se.what()); 35 assert(what_message.find(what_arg) != std::string::npos); 36 assert(what_message.find(std::iostream_category().message(static_cast<int> 37 (std::io_errc::stream))) != std::string::npos); 38 } 39} 40