的字符串刪除標點符號有書中C++ Primer(數3.2.3)它要求一個練習:從人物
Write a program that reads a string of characters including punctuation and writes what was read but with the punctuation removed.
我試圖解決這個問題,但得到了一個錯誤:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cin >> "Enter a sentence :" >> s >> endl;
for (auto c : s)
if (ispunct(c))
remove punct;
cout << s << endl;
}
...錯誤究竟是什麼? – Columbo 2014-10-11 16:01:50
你應該在你的'if'和'for'語句中使用大括號來避免含糊不清。另外,'remove punct'沒有任何意義。 – 0x499602D2 2014-10-11 16:04:19
正如你所看到的,這個問題並不需要你存儲結果。如果不是標點符號,爲什麼不逐一寫出每個字符? – 2014-10-11 16:04:31