私はこのプロジェクトに取り組んでいます。ここには日付が含まれています:str1-> "01/17/17" str2 - > "12/29/16" atoiやstoiなどの変換機能を使用することはできません。 私は文字列の各文字を見て、どれが少ないかを見るためにそれらを比較しています。 str1の月が< = str2の場合、ブール配列をtrueに設定します。私は明らかに間違っています。私は、異なるデータ型に変換することを伴わない単純な解決策は考えられませんが、私はそうすることは許されません。私は大いに助けてくれる誰にでも感謝します。優先順位(年>月>日)の、後は見つけるので、は、フォーマットされたデータを含む文字列を比較します
sortData(items);
bool date[5];
date[0] = false; //month
date[1] = true; // '/'
date[2] = false; //day
date[3] = true; // '/'
date[4] = false; //year
//looking for smallest string
string str1;
string str2;
for (int i = 4; i < 7; i++)
{
str1 = items[i].date;
str2 = items[i + 1].date;
int size = str1.length();
int count = 0;
while (count < size)
{
if (str1[count] <= str2[count] || str1[count + 1] <= str2[count + 1])
{
date[0] = true;
}
//0,1
count=count+3; //3,4
if (str1[count] <= str2[count] || str1[count + 1] <= str2[count + 1])
date[2] = true; //day
count = count + 3;
//6,7
if (str1[count] <= str2[count] || str1[count + 1] <= str2[count + 1])
date[4] = true;
count=count+1;
}
}
int m = 0; //for debugging
入出力の例はなく、エラーはありませんか?まあ、char '0'はchar '1'よりも小さいので、日、月、年があるだけなので、しばらくするのはナイスで、優先順位(年 - >月 - >日) – cpatricio