您好我想知道什麼是使串STR1似乎等於字符串STR2的最短途徑C++比較字符串例如,當忽略前面的空格:「STR1」比較(」 STR2" )= TRUE
str1 = "Front Space";
str2 = " Front Space";
/*Here is where I'm missing some code to make the strings equal*/
if (str1.compare(str2) == 0) { // They match
cout << "success!!!!" << endl; // This is the output I want
}
所有我需要它爲str1等於str2 我該怎麼做?
我已經做了多次嘗試,但他們似乎都沒有正常工作。我認爲這是因爲字符串中的字符數量,即:str1的字符數少於str2。
for (int i = 1; i <= str1.length() + 1; i++){
str1[str1.length() - i ] = str1[str1.length() - (i + 1)];
}
任何幫助表示讚賞