警告:在 C++ 中比较数组和字符串
warning: in c++ compare array and string
我有这个警告:
警告:多字符字符常量 [-Wmultichar]
被告是:
if (strchr(test[0],'E3')){
如果我编辑
if (strchr(test[0],"E1")){
我有这个错误:
错误:从"常量字符*"到"整数"的转换无效 [-允许]
考虑测试[0]声明为:
char *test[10];
我该如何解决?
为什么不使用 std::string::find?
std::string str(test[0]);
auto idx = str.find("E3");
这是函数原型:
const char * strchr ( const char * str, int character );
strchr() 函数返回指向第一次出现的指针字符串 S 中的字符 C。
您对函数原型的使用是错误的。
if (strchr(test[0],"E1")){
因此,编译器出错。
''
将为您提供要搜索的字符的 ASCII 值。
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in "%s"...n",str);
pch=strchr(str,'s');
相关文章:
- 使用 jsoncpp 解析 json 数组字符串
- C++ 对象数组字符串输入在控制台上不起作用
- 插入了 C++ 数组字符串数据,但在显示输出时不显示
- 无法区分 JSON 对象/数组/字符串
- 为什么数组(字符串类型)的大小是 24 字节,带有单个空格元素
- 如何使用数组字符串进行输入验证
- (C++) 打印字符数组字符串的单词时出现问题
- 使用Back_inserter从任何位置的输入字符中使用Back_inserter进行过滤数组字符串
- C 函数反转字符数组字符串
- 如何在 c++ 中创建数组(字符串 [] )的向量
- 如何返回数组字符串的指针
- char数组字符串混淆
- 如何从字符数组字符串中提取空格
- 是否可以将 Bitset<8> 的值复制到数组字符串而不转换它们?
- C++数组字符串函数
- 如何在函数中操作字符数组(字符串)的指针,该指针在C / C ++中作为参数传递
- visual将音频文件存储到数组/字符串流C++中
- c++在char数组(字符串)上将what替换为
- 将数组字符串转换为intger c++(初学者)
- 需要设置数组字符串长度,使其恰好为13