File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ # getenv
2+ * cstdlib[ meta header]
3+ * std[ meta namespace]
4+ * function[ meta id-type]
5+
6+ ``` cpp
7+ char * getenv ( const char* env_var );
8+ ```
9+
10+ ## 概要
11+
12+ ホスト環境(OS)が提供する環境リストから、Cストリング`env_var`と一致する文字列を検索、一致したもののポインタを返す
13+
14+ ## 返り値
15+
16+ 一致したものがあれば環境変数を保持した文字列、なければヌルポインタを返す
17+
18+ ## 備考
19+
20+ C++11以前は、他の関数でホスト環境が変更されなければ、この関数はスレッドセーフである。(他のスレッドで呼び出された場合でも)
21+
22+ C++11以降では、`getenv`が返す文字列を変更すると未定義動作となる。
23+
24+ ## 例
25+ ```cpp example
26+ #include <cstdlib>
27+ #include <iostream>
28+
29+ int main()
30+ {
31+ if (const char* env_p = std::getenv("PATH"))
32+ std::cout << "Your PATH is: " << env_p << '\n';
33+ }
34+ ```
35+
36+ ## 出力結果
37+ ```
38+ Your PATH is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
39+ ```
40+
You can’t perform that action at this time.
0 commit comments