この問題が頻繁に発生することは知っていますが、うまく機能するコードが見つかりませんでした。
文字列ライブラリの find_first_not_of メソッドと find_last_not_of メソッドを使用して、着信文字列からすべての句読点を取り除こうとしています。
//
//strip punctuation characters from string
//
void stripPunctuation(string &temp)
{
string alpha = "abcdefghijklmnopqrstuvwxyz";
size_t bFound = temp.find_first_not_of(alpha);
size_t eFound = temp.find_last_not_of(alpha);
if(bFound != string::npos)
temp.erase(temp.begin());
if(eFound != string::npos)
temp.erase(temp.end());
}
基本的に、アルファベットではない文字列の先頭とアルファベットではない文字列の末尾にあるものはすべて削除したいと考えています。この関数が呼び出されると、セグメンテーション違反が発生します。bFound と eFound をどこに渡す必要があるかわかりません。