C++ forbids comparison between pointer and integer

Here's the code:

struct resident{
.
.
string lastName;
.
.
};

void LastNameCheck(resident[]){

for(int i = 0; i < lastName.length(); i++)
if(!isalpha(lastName[i]) && lastName[i] != "-" )// <-- error is here

The point is to check the string character by character to make sure it is either a letter or a hyphen. The record contains several different residents, and passing each in one at a time or copying each record to a local 'resident' (struct) both seem like really poor ways of getting around this comparison thing.

Help?





















C++ forbids comparison between pointer and integer
Last edited on
The open() methods don't take strings, only char*.
 
inData.open(INFILE.c_str());

Hope this helps.


[edit]
What!? That's not the post I responded to.
Last edited on
You are comparing a char (integer) with a const char* (a pointer):
lastName[i] != "-"

Don't do that. Instead compare chars with chars:
lastName[i] != '-'

Good luck!
Topic archived. No new replies allowed.