Deprecated: Array and string offset access syntax with curly braces is deprecated in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/init.php on line 542
ja:cpp [GiriWiki]

ユーザ用ツール

サイト用ツール


ja:cpp

以前のリビジョンの文書です



Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/parser/handler.php on line 1458

Warning: Declaration of syntax_plugin_note::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/lib/plugins/note/syntax.php on line 79

Warning: Declaration of syntax_plugin_note::render($mode, &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/lib/plugins/note/syntax.php on line 101

Warning: preg_match(): Compilation failed: invalid range in character class at offset 3120 in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/parser/lexer.php on line 118
A PCRE internal error occured. This might be caused by a faulty plugin

====== C++ の備忘録 ====== ===== ストリーム ===== ==== 標準出力に出力 ==== <code c> double d1 = 123.456; double d2 = 234.567; std::cout << d1 << " , " << d2 << std::endl; </code> この出力は、\\ 123.456 , 234.567\\ となる。 <code c> std::cout << d1 << " , " << std::flush; std::cout << d2 << endl; </code> でも上と同じ出力。 === 出力の精度、桁数指定をしたい === <code c> std::cout << std::setprecision(5) << d1 << " , " << std::flush; std::cout << d2 << endl; </code> とすると、出力は\\ 123.46 , 234.57\\ となる。 * std::setprecision(n) で表示する全桁数(有効数字)を指定 * 一度指定すると、その設定がそのまま引き継がれる。 <code c> std::cout << std::fixed << std::setprecision(1) << d1 << " , " << std::flush; std::cout << d2 << endl; </code> とすると、出力は\\ 123.5 , 234.6\\ となる。 * std::fixed と std::setprecision(n) を合わせて使うことによりnは”小数点以下の桁数”の意味になる。 * これまた引き継がれる。 ===== フォーマット指定 ===== * デフォルトではフォーマット指定はfloat (%f) * 以下、std::は省略(using namespace std) ^ ^ stdio ^ iostream ^出力結果 ^ | 整数10進法表記 | printf(“%d”,123); | cout << dec << 123 << endl; | 123 | | 固定小数点表記 | printf(“%f”,1.2345); | cout << fixed << 1.2345; |1.234500| | ::: | printf(“%.2f”,1.2345); | cout << fixed << setprecision(2) << 1.2345; | 1.23 | | 指数表記 | printf(“%e”,1.2345); | cout << scientific << 1.2345; | 1.234500+e000 | | ::: | printf(“%.2E”,1.2345); | cout << scientific << setprecision(2) << uppercase << 1.2345; | 1.23+E000 | | 0埋め | printf(“%05d”,123); | cout << setfill(’0′) << setw(5) << right << 123; | 00123| | 左寄せ | printf(“%5d”,123); | cout << setw(5) << left << 123; | 123 | | 右寄せ | printf(“%5-d”,123); | cout << setw(5) << right << 123; | 123 | | 正号表示 | printf(“%+d”,123); | cout << showpos << 123; | +123 | * デフォルトに戻すには、 <code c> cout << resetiosflags(ios_base::floatfield); </code> のようにする。

ja/cpp.1406858864.txt.gz · 最終更新: 2014/08/01 02:07 by kota