Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::errc

      From cppreference.com
      <cpp‎ |error
       
       
      Utilities library
       
      Diagnostics library
       
      std::errc
       
      Defined in header<system_error>
      enumclass errc;
      (since C++11)

      The scoped enumerationstd::errc defines the values of portable error conditions that correspond to the POSIX error codes.

      Contents

      [edit]Member constants

      Name Equivalent POSIX Error
      address_family_not_supportedEAFNOSUPPORT
      address_in_useEADDRINUSE
      address_not_availableEADDRNOTAVAIL
      already_connectedEISCONN
      argument_list_too_longE2BIG
      argument_out_of_domainEDOM
      bad_addressEFAULT
      bad_file_descriptorEBADF
      bad_messageEBADMSG
      broken_pipeEPIPE
      connection_abortedECONNABORTED
      connection_already_in_progressEALREADY
      connection_refusedECONNREFUSED
      connection_resetECONNRESET
      cross_device_linkEXDEV
      destination_address_requiredEDESTADDRREQ
      device_or_resource_busyEBUSY
      directory_not_emptyENOTEMPTY
      executable_format_errorENOEXEC
      file_existsEEXIST
      file_too_largeEFBIG
      filename_too_longENAMETOOLONG
      function_not_supportedENOSYS
      host_unreachableEHOSTUNREACH
      identifier_removedEIDRM
      illegal_byte_sequenceEILSEQ
      inappropriate_io_control_operationENOTTY
      interruptedEINTR
      invalid_argumentEINVAL
      invalid_seekESPIPE
      io_errorEIO
      is_a_directoryEISDIR
      message_sizeEMSGSIZE
      network_downENETDOWN
      network_resetENETRESET
      network_unreachableENETUNREACH
      no_buffer_spaceENOBUFS
      no_child_processECHILD
      no_linkENOLINK
      no_lock_availableENOLCK
      no_message_available(deprecated)ENODATA
      no_messageENOMSG
      no_protocol_optionENOPROTOOPT
      no_space_on_deviceENOSPC
      no_stream_resources(deprecated)ENOSR
      no_such_device_or_addressENXIO
      no_such_deviceENODEV
      no_such_file_or_directoryENOENT
      no_such_processESRCH
      not_a_directoryENOTDIR
      not_a_socketENOTSOCK
      not_a_stream(deprecated)ENOSTR
      not_connectedENOTCONN
      not_enough_memoryENOMEM
      not_supportedENOTSUP
      operation_canceledECANCELED
      operation_in_progressEINPROGRESS
      operation_not_permittedEPERM
      operation_not_supportedEOPNOTSUPP
      operation_would_blockEWOULDBLOCK
      owner_deadEOWNERDEAD
      permission_deniedEACCES
      protocol_errorEPROTO
      protocol_not_supportedEPROTONOSUPPORT
      read_only_file_systemEROFS
      resource_deadlock_would_occurEDEADLK
      resource_unavailable_try_againEAGAIN
      result_out_of_rangeERANGE
      state_not_recoverableENOTRECOVERABLE
      stream_timeout(deprecated)ETIME
      text_file_busyETXTBSY
      timed_outETIMEDOUT
      too_many_files_open_in_systemENFILE
      too_many_files_openEMFILE
      too_many_linksEMLINK
      too_many_symbolic_link_levelsELOOP
      value_too_largeEOVERFLOW
      wrong_protocol_typeEPROTOTYPE

      [edit]Non-member functions

      creates error code value forerrc enume
      (function)[edit]
      creates an error condition for anerrc valuee
      (function)[edit]

      [edit]Helper classes

      extends the type traitstd::is_error_condition_enum to identifyerrc values as error conditions
      (function template)[edit]

      [edit]Example

      Run this code
      #include <filesystem>#include <fstream>#include <iomanip>#include <iostream>#include <string>#include <system_error>#include <thread> void print_error(conststd::string& details,std::error_code error_code){std::string value_name;if(error_code== std::errc::invalid_argument)        value_name="std::errc::invalid_argument";if(error_code== std::errc::no_such_file_or_directory)        value_name="std::errc::no_such_file_or_directory";if(error_code== std::errc::is_a_directory)        value_name="std::errc::is_a_directory";if(error_code== std::errc::permission_denied)        value_name="std::errc::permission_denied"; std::cout<< details<<":\n  "<<std::quoted(error_code.message())<<" ("<< value_name<<")\n\n";} void print_errno(conststd::string& details,int errno_value=errno){    print_error(details,std::make_error_code(std::errc(errno_value)));} int main(){std::cout<<"Detaching a not-a-thread...\n";try{std::thread().detach();}catch(conststd::system_error& e){        print_error("Error detaching empty thread", e.code());} std::cout<<"Opening nonexistent file...\n";std::ifstream nofile{"nonexistent-file"};if(!nofile.is_open())        print_errno("Error opening nonexistent file for reading"); std::cout<<"Reading from directory as a file...\n";std::filesystem::create_directory("dir");std::ifstream dir_stream{"dir"};[[maybe_unused]]char c= dir_stream.get();if(!dir_stream.good())        print_errno("Error reading data from directory"); std::cout<<"Open read-only file for writing...\n";std::fstream{"readonly-file", std::ios::out};std::filesystem::permissions("readonly-file",std::filesystem::perms::owner_read);std::fstream write_readonly("readonly-file", std::ios::out);if(!write_readonly.is_open())        print_errno("Error opening read-only file for writing");}

      Possible output:

      Detaching a not-a-thread...Error detaching empty thread:  "Invalid argument" (std::errc::invalid_argument) Opening nonexistent file...Error opening nonexistent file for reading:  "No such file or directory" (std::errc::no_such_file_or_directory) Reading from directory as a file...Error reading data from directory:  "Is a directory" (std::errc::is_a_directory) Open read-only file for writing...Error opening read-only file for writing:  "Permission denied" (std::errc::permission_denied)

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3869C++11the member constantsno_message_available,
      no_stream_resources,not_a_stream andstream_timeout
      referred to the obsolete POSIX STREAMS API[1]
      deprecated them
      1. Although the corresponding POSIX error numbers ENODATA, ENOSR, ENOSTR and ETIME were marked "obsolescent" in POSIX 2017, the STREAMS API was optional and not required for conformance to the previous POSIX standard (because popular unix-like systems refused to implement it).

      [edit]See also

      (C++11)
      holds a platform-dependent error code
      (class)[edit]
      holds a portable error code
      (class)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/errc&oldid=173417"

      [8]ページ先頭

      ©2009-2025 Movatter.jp