I want to copy every character that is not a symbol or punctuation into a new string variable using isalpha() and isdigit(). The compiler throws an error saying "string subscript out of range." Thanks in advance for your help.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string new_string;
string edited_string;
cout << "Please type a sentence or numbers...\n";
getline(cin, new_string);
int count = 0;
for (int x = 0; x < new_string.length(); x++)
{
if (isalpha(new_string[x]) || isdigit(new_string[x]))
{
edited_string[count] = new_string[x]; // THIS is the line with problem
count = count + 1;
}
}
return 0;
}
oh no at all. Your solution is much simpler. My solution consisted of "reinventing the wheel", while yours was "replace the only the lug-nut." Thanks for jumping in.