標準出力でのpause

  • cin.ignore, cin.get, getcharなどが使える


[]// reg_sp_tok.cpp : コンソール アプリケーションのエントリ ポイントを定義します。[]
[]//[]

[]#include[][] "stdafx.h"[]

[]#include[][] <iostream>[]
[]#include[][] <vector>[]
[]#include[][] <string>[]


[]#include[][] <boost/spirit/core.hpp>[]
[]#include[][] <boost/spirit/actor/push_back_actor.hpp>[]
[]#include[][] <boost/cast.hpp>[]
[]#include[][] <boost/type_traits.hpp>[]

[]#include[][] <boost/static_assert.hpp>[]
[]#include[][] <boost/mpl/sizeof.hpp>[]

[]// Original: http://www.boost.org/libs/spirit/doc/quick_start.html[]

[]namespace[] []pst[] {

[]using[] []namespace[] []std[];
[]namespace[] []bst[] = []boost[];
[]namespace[] []spl[] = []boost[]::[]spirit[];
[]namespace[] []mpl[] = []boost[]::[]mpl[];

[]bool[] []parse_numbers[]([]wchar_t[] []const[]* []str[], []vector[]<[]double[]>& []v[])
{
[]return[] []spl[]::[]parse[](
[]str[],
(
[]spl[]::[]real_p[][[]spl[]::[]push_back_a[]([]v[])]
>> *([]L[][]','[] >> []spl[]::[]real_p[][[]spl[]::[]push_back_a[]([]v[])])
),
[]spl[]::[]space_p[]).[]full[];
}

[]void[] []main[]()
{
[]wcout[] << []L[][]"/////////////////////////////////////////////////////////\n\n"[];
[]wcout[] << []L[][]"\tコンマで区切られた数値のSpiritによる解析器...\n\n"[];
[]wcout[] << []L[][]"/////////////////////////////////////////////////////////\n\n"[];
[]wcout[] << []L[][]"終了したいときは、qかQをタイプしてください\n\n"[];

[]wstring[] []str[];
[]while[] ([]getline[]([]wcin[], []str[]))
{
[]if[] ([]spl[]::[]parse[]([]str[].[]c_str[](), []spl[]::[]as_lower_d[][[]L[][]'q'[]]).[]full[]) []// (str[0] == L'q' || str[0] == L'Q')[]
[]break[];

[]vector[]<[]double[]> []v[];
[]if[] ([]parse_numbers[]([]str[].[]c_str[](), []v[])) {
[]wcout[] << []L[][]"-------------------------\n"[];
[]wcout[] << []L[][]"解析成功\n"[];
[]wcout[] << []str[] << []L[][]" の解析完了: "[] << []endl[];

[]for[] ([]vector[]<[]double[]>::[]size_type[] []i[] = 0; []i[] < []v[].[]size[](); ++[]i[]) {
[]// Note: I can't find "static"_numeric_cast from boost...[]
[]BOOST_STATIC_ASSERT[]( []mpl[]::[]sizeof_[]<[]size_t[]>::[]value[] <= []mpl[]::[]sizeof_[]<[]unsigned[] []int[]>::[]value[] );
[]wcout[] << []static_cast[]<[]unsigned[] []int[]>([]i[]) << []L[][]": "[] << []v[][[]i[]] << []endl[];
}

[]wcout[] << []L[][]"-------------------------\n"[];
} []else[] {
[]wcout[] << []L[][]"-------------------------\n"[];
[]wcout[] << []L[][]"解析失敗\n"[];
[]wcout[] << []L[][]"-------------------------\n"[];
}
}

[]wcout[] << []L[][]"さよなら... (^^) \n\n"[];

{ []// See: http://www.codingforums.com/showthread.php?t=53320[]
[]wcin[].[]ignore[]();
[]// wchar_t pause;[]
[]// wcin >> pause;[]
}
}
}

[]int[] []main[]()
{
[]std[]::[]locale[]::[]global[]([]std[]::[]locale[]([]"ja"[]));
{ []// See: http://hw001.gate01.com/eggplant/tcf/cpp/wchar_t_trap.html[]
[]std[]::[]wcin[].[]imbue[]([]std[]::[]locale[]([]"ja"[]));
[]std[]::[]wcout[].[]imbue[]([]std[]::[]locale[]([]"ja"[]));
}

[]pst[]::[]main[]();

[]return[] 0;
}