私のコードの1つの機能で、私はバグを発見しました。書かれたstd:string
:std:stringとstd :: stringの違い
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
//strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
strftime(buf, sizeof(buf), "%Y%m%d%X", &tstruct);
std:string str = buf;
str.erase(std::remove(str.begin(), str.end(), ':'), str.end());
return str;
}
コードはエラーの無い状態でコンパイルされます。なぜそれはコンパイルされますか?それではstd:string
はどういう意味ですか?
'std:'はラベルであり、どこかで使用する必要があります。 –
このコードは、 "using namespace std"を実行していて、IMOが悪い場合にのみ機能します。さもなければ定義されたタイプ文字列がない限り、これはコンパイルエラーとして捕らえられていました。 – Devolus
@Devolus std :: stringを使って同じ効果を得ることもできます。 – dascandy