检查字符是否为单引号.c++

check if a char is a single quote. c++

本文关键字:单引号 c++ 是否 字符 检查      更新时间:2023-10-16

我想检查一个字符是否是单引号。这是我的密码。

char mychar;
if (mychar == ''')  // Is that how we check this char is a single quote?
{
  cout << "here is a quote" << endl;
}

您的代码片段无效。代替

char mychar;
if(char==''')// is that how we check this char is a single quote?
{
  cout<<"here is a quote"<<endl;
}

必须有

char mychar;
if(mychar==''')// is that how we check this char is a single quote?
{
  cout<<"here is a quote"<<endl;
}

而且对象CCD_ 1必须被初始化。

至于其他那个么你们必须使用包含单引号转义符的文字。

或者如果你有一个字符串文字像

const char*quote="'";

然后你可以写为

if( mychar == *quote )

if( mychar == quote[0] )

是。(假设您修复了char而不是mychar的拼写错误。)