I want to check if a char is a single quote. Here is my code.
char mychar;
if (mychar == '\'') // Is that how we check this char is a single quote?
{
cout << "here is a quote" << endl;
}
Your code snippet is invalid. Instead of
char mychar;
if(char=='\'')// is that how we check this char is a single quote?
{
cout<<"here is a quote"<<endl;
}
there must be
char mychar;
if(mychar=='\'')// is that how we check this char is a single quote?
{
cout<<"here is a quote"<<endl;
}
And moreover object mychar
must be initialized.
As for other then indeed you have to use character literal that contains escape symbol of single quote.
Or if you have a string literal like
const char *quote = "'";
then you can write either as
if( mychar == *quote )
or
if( mychar == quote[0] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With