C ++ introduction: self study

I need help for my program for the following code. I work, thanks "paxdiablo". The result still shows the "\" character. How can i fix this? (not sure how to reply "paxdiablo" to sya thanks.

if (strchr (",.();:-\"&?%$![]^@~`{}_<>/#*_+=", curChar) != NULL)//new change
{
   paragraph.erase(subscript, 1);
   numWords-=1;
}
else 
   subscript+=1;

}
+3
source share
5 answers

Not expert C, but try to exit \

if (strchr ("\\,.();:-\"&?%$![]^@~`{}_<>/#*_+=", curChar) != NULL)//new change
+5
source

See how the string you match with has \"in it?

This is an escape sequence. He tells the C ++ compiler: "I want the character to "be in this string literal." You have to say this in a special way, because it usually "marks the end of a line.

\ , escape-. , , , escape-. , escape-.

\, , \\.

+2

'\', :

if (strchr (",.();:-\\\"&?%$![]^@~`{}_<>/#*_+=", curChar) != NULL)

, \", ". \, \\, .

+1

\ escape- ( "). \\ .

if (strchr (",.();:-\"&?%$![]^@~`{}_<>/#*_+=\\", curChar) != NULL)
+1

Try executing it: \\instead\

+1
source

Source: https://habr.com/ru/post/1778417/


All Articles