time_get::get_time
將字串剖析為 strftime的 X 規範所產生的日期。
iter_type get_time(
iter_type _First,
iter_type _Last,
ios_base& _Iosbase,
ios_base::iostate& _State,
tm* _Pt
) const;
參數
_First
輸入定址 Iterator 要轉換之序列的開頭。_Last
輸入定址 Iterator 要轉換之序列的結尾。_Iosbase
未使用。_State
設定資料流的狀態的適當的位元遮罩項目,根據可能選擇作業可能會成功。_Pt
陣列的指標要存放的本機日期資訊。
傳回值
處理輸入的 Iterator 在輸入欄位以外的第一個項目。
備註
成員函式傳回 do_get_time(_First、 _Last、 _Iosbase、 _State, _Pt)。
範例
// time_get_get_time.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
#include <time.h>
using namespace std;
int main( )
{
locale loc;
basic_stringstream<char> pszGetF, pszPutF, pszGetI, pszPutI;
ios_base::iostate st = 0;
struct tm t;
memset( &t, 0, sizeof( struct tm ) );
pszGetF << "11:13:20";
pszGetF.imbue( loc );
basic_istream<char>::_Iter i = use_facet
<time_get <char> >
(loc).get_time(basic_istream<char>::_Iter(pszGetF.rdbuf( )),
basic_istream<char>::_Iter(0), pszGetF, st, &t);
if (st & ios_base::failbit)
cout << "time_get::get_time("<< pszGetF.rdbuf( )->str( )<< ") FAILED on char: " << *i << endl;
else
cout << "time_get::get_time("<< pszGetF.rdbuf( )->str( )<< ") ="
<< "\ntm_sec: " << t.tm_sec
<< "\ntm_min: " << t.tm_min
<< "\ntm_hour: " << t.tm_hour
<< endl;
}
需求
標題: <locale>
命名空間: std