文字列やベクトル列に割り当てる時間にはCTime&いるasctimeを使用して

StackOverflow https://stackoverflow.com/questions/4200504

  •  25-09-2019
  •  | 
  •  

質問

私は文字列に時間を割り当てるためにいるasctimeを使用したいと思います。

time_t rawtime;
time ( &rawtime );
vector<string> TTime;
TTime.resize(10);
TTime = asctime(localtime ( &rawtime ));

私がいるasctimeは文字列へのポインタを返して理解しています。私は自分自身の文字列を作成し、それにいるasctimeの戻り値を代入する必要がある、または単純な方法はありますか?

役に立ちましたか?

解決

あなたはchar *から直接文字列を構築することができます:

string str = asctime(localtime ( &rawtime ));

これは意味をなさないます:

TTime = asctime(localtime ( &rawtime ));

あなたは、文字列のベクトルに単一の文字列を割り当てることはできません。何のできないことはあります:

TTime[0] = asctime(localtime ( &rawtime ));

他のヒント

あなたが必要なもののように見えますが、単純な文字列で、

std::string TTime(asctime(localtime(&rawtime)));

関数関数は、asctime()の戻りのchar * そして、std :: stringは文字から構築することができます*

のstd ::文字列の時間(いるasctime(LOCALTIME(&rawtime)));

または

のstd ::文字列の時間。 時間=いるasctime(asctimer(localtimer(&rawtime)));

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top