嗨,我想知道什么是使字符串str1看起来等于字符串str2的最短方法
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
}
Run Code Online (Sandbox Code Playgroud)
所有我需要它str1等于str2我该怎么办?
我做了多次尝试,但它们似乎都没有正常工作.我认为这是因为字符串中的字符数,即:str1的字符数少于str2.
for (int i = 1; i <= str1.length() + 1; i++){
str1[str1.length() - i ] = str1[str1.length() - (i + 1)];
}
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏