의 문자열에서 구두점을 제거하면이 요청 책 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
모호성을 피하기 위해'if'와'for' 문 주위에 중괄호를 사용해야합니다. 또한,'punct '를 제거하는 것은 말이되지 않습니다. – 0x499602D2
보시다시피 질문에 결과를 저장할 필요가 없습니다. 모든 문자를 하나씩 탐색합니다. 왜 구두점이 아닌 문자를 하나씩 쓰지 않는 것이 좋을까요? –