現在の日付を返す関数を作成しました。関数内では、結果を「cout」して機能しますが、関数を「cout」すると機能しません。ゴミが出ました。
const char* engineCS::getDate() const
{
time_t t = time(0);
struct tm *now = localtime(&t);
char buf[20];
strftime(buf, sizeof(buf), "%Y-%m-%d %X", now);
cout << buf << endl;
return buf;
}
例:内部:2012-02-02 00:00:00外部:????? fv
なにが問題ですか?同様の問題:関数と戻り値const char *
THX
編集:今何が問題になっていますか?申し訳ありませんが、VB.NETをやりすぎました...
const char* engineCS::getDate() const
{
time_t t = time(0);
struct tm *now = localtime(&t);
char *buf;
buf = new char[20];
strftime(buf, sizeof(buf), "%Y-%m-%d %X", now);
cout << buf << endl;
return buf;
}