I am in a c++ class and I am doing a program which requires me to read in a text file and do change it. I need to know if something is in " " or ' ' to do this program. I can get the " " by doing

if(char == '"'){}

but when I try the other one it looks like

if(char == '''){}

and I gets errors because I think the compiler thinks the second ' is the closing one and the third is just a mistake or something.

Can someone please help.

Your assumption is correct. You need to escape it:

if(char == '\''){}

Also, you need to use code tags.

I am in a c++ class and I am doing a program which requires me to read in a text file and do change it. I need to know if something is in " " or ' ' to do this program. I can get the " " by doing

if(char == '"'){}

but when I try the other one it looks like

if(char == '''){}

and I gets errors because I think the compiler thinks the second ' is the closing one and the third is just a mistake or something.

Can someone please help.

you need to use an escaped character

if( someChar == '\'' ){}

Your assumption is correct. You need to escape it:

if(char == '\''){}

Also, you need to use code tags.

Thank you very much it worked.

I am in a c++ class and I am doing a program which requires me to read in a text file and do change it. I need to know if something is in " " or ' ' to do this program. I can get the " " by doing

if(char == '"'){}

but when I try the other one it looks like

if(char == '''){}

and I gets errors because I think the compiler thinks the second ' is the closing one and the third is just a mistake or something.

Can someone please help.

if you are testing on a character variable then do the following :

char c;

if( c == '\'')

Comments
three hours after he acknowledged the answer you post this? You need to read the threads before posting.
This article has been dead for over six months. Start a new discussion instead.