我寫了一個功能空間&之前刪除從一個句子的空間,但其只考慮字符不考慮整個句子。 如果我跑了這一點賣出期權我已經寫了一個函數從一個句子中的空格,但其只考慮字符的空間之前和不考慮整個森泰斯
Enter the string with space/ tab to trim
IamDoing very fine
Length of the String is : 8
IamDoing
我什麼樣的變化,我需要做得到「IamDoingveryfine」 請幫幫忙,代碼如下......」
void removeSpace(const string &str)
{
string tempStr;
string p_str = str;
int l_length = p_str.length();
cout<<"Length of the String is : "<<l_length<<endl;
for (int i=0; i<l_length; i++)
{
if(p_str[i] != ' ' || p_str[i] != '\t')
{
tempStr +=p_str[i]; //to add chars into tempstr
}
}
cout<<tempStr<<'\n';
return ;
}
請你能張貼在那裏你字符串中讀取的代碼,你應該做'的std ::函數getline()'取代'的std :: CIN >>讀入。而你的'||'應該是'&&'。 –
所有字符與空格和製表符中的至少一個不同。 「如果字符不是空格或製表符」,則將其翻譯爲「如果字符不是空格且字符不是製表符」。 – molbdnilo
德摩根定理:「如果它是一個空格或製表符,則將其刪除」與「如果它不是空格**和**而不是製表符」保持一致。這就是說,這是一個容易犯的錯誤。 –