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.

Recommended Answers

All 4 Replies

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 == '\'')

commented: three hours after he acknowledged the answer you post this? You need to read the threads before posting. -2
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.