フォームの日付strVal="1992-12-12"または"1992-9-9"を19921212および19920909に変換したいと思います。そのために、次のコードをC /C++で記述しました。しかし、問題はそれが1992-12-12を1992012012に変換することです。このバグをどのように修正するかについて誰かが私を導くことができますか?「1992-9」という形式の入力もあるかもしれませんが、それを19920900に変換したいと思います。または「1992」から「19920000」に変換したいのですが。
stringstream collectTimeBegin;
for (string::iterator it = strVal.begin(); it != strVal.end(); )
{
if (*it != '-')
{
cout<< "\n -- *it=" << *it;
collectTimeBegin << *it;
it++;
}
else
{
stringstream si("");
stringstream sj("");
int i;
it++;
si << *(it + 1);
sj<< *(it + 2);
i = atoi((si.str()).c_str()), j = atoi((sj.str()).c_str());
cout << "\n i=" << i << "\t j=" << j << "\n";
if ((i == 4) || (i == 5) || (i == 6) || (i == 7) || (i == 8) || (i == 9))
{
cout << "\n 1. *it=" << *it;
collectTimeBegin << *it;
it++;
}
else if ((j == 0) || (j == 1) || (j == 2) || (j == 3) || (j == 4) ||
(j == 5) || (j == 6) || (j == 7) || (j == 8) || (j == 9))
{
string str = "0";
cout << "\n 2. *it=" << *it;
collectTimeBegin << str;
collectTimeBegin << *it;
it++;
}
}
}