Hi

I have a function where if the first character of a string is whitespace it then deletes it.

My problem is I am getting an error on a certain line & I have no idea why & how to fix it.

error:

C++ forbids comparison between pointer and integer

Function:

void delete_whitespace(string array[], int array_size)
{

               for (int i = 0; i < array_size; i++)
	{

		if ( array[i][0] == " " )  // This is the line where the error occurs
		{
			array[i].erase(0,1);
		}
	}

	}

Attempting to compare a single character with a string. Here is how to fix it -- use single quotes instead of double quotes array[i][0] == ' '

commented: You should have suggested " "[0] ;) +35

Ah silly me :P Its so obvious now :) Thank you

I dont know why elcipse doesn't just give an error of "invadid comparision of char with string" or sumthing instead of talking about ints?

Thanks again :)

>why elcipse doesn't just give an error of "invadid comparision of char with string" or sumthing instead of talking about ints?

Well, actually it does something like that:

C++ forbids comparison between pointer and integer

The pointer where the compiler is complaining about was the string with the double quotes: " " , the integer where the compiler was complaining about is the character from the string where you want to compare with (In C++ a character can be implicitly converted to an integer) ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.