char配列から空白や特殊文字を削除する手助けが必要です。私が間違っていない場合、erase関数は文字列データ型でのみ機能します。私はそれを変換することはできませんまたは文字列変数を持つ文字列ではない文字配列の代入を呼び出します。私はそれを探してみましたが、それは文字列に変換するか、文字列として開始することを示唆しています。私はプログラミングに慣れておらず、ポインタは私にとっては少し変わっているので、答えが明らかであれば私はごめんなさい。助けてくださったみなさん、ありがとうございました。ポインタを使用してchar配列[]から文字を削除/削除する
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
int main()
{
const int SIZE = 80;
char str[SIZE];
char* strPtr;
int strlength;
int j = 0;
int front = 0, back; int flag = 1;
strPtr = str;
cout << "This program checks for palidromes." << endl;
cout << "Please enter a phrase." << endl;
cout << endl;
cin.getline(str, SIZE);
//Get the length of string str
strlength = strlen(str);
//Convert all the characters in the string str to uppercase
for (int i = 0; i < strlength; i++)
{
if (!isupper(str[i]))
str[i] = toupper(str[i]);
}
//Remove all the special characters except letters a - z
for (int i = 0; i < strlength; i++)
if (!isalpha(str[i])||(!isalnum(str[i])))
{
str.erase(str[i]); // need help here. Not sure how to go about it.
}
//str[j] = '\0';
return 0;
}
私は実際にラムダの使用が好きです。 +1 –