GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::getenv - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. cstdlib
  3. getenv

最終更新日時: 2025年07月12日 02時16分44秒 (JST)
Koichi Murase が更新

履歴 編集

function
<cstdlib>

std::getenv

namespace std {
  char* getenv( const char* env_var );
}

概要

ホスト環境(OS)が提供する環境リストから、Cストリングenv_varと一致する文字列を検索、一致したもののポインタを返す

戻り値

一致したものがあれば環境変数を保持した文字列、なければヌルポインタを返す

備考

C++11以前は、他の関数でホスト環境が変更されなければ、この関数はスレッドセーフである。(他のスレッドで呼び出された場合でも)

C++11以降では、getenvが返す文字列を変更したときの動作は未定義である。

例

#include <cstdlib>
#include <iostream>

int main()
{
  if (const char* env_p = std::getenv("PATH"))
    std::cout << "Your PATH is: " << env_p << '\n';
}

出力例

Your PATH is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.