gpt4 book ai didi

c++ - 获取错误 : "ISO C++ forbids comparison between pointer and integer [-fpermissive]" How do I fix?

转载 作者:行者123 更新时间:2023-11-30 02:34:05 32 4
gpt4 key购买 nike

我正在制作一个将英语句子转换成 pig latin 的程序。我在第 16 行不断收到错误“ISO C++ 禁止比较指针和整数 [-fpermissive]”。有什么帮助吗?

void wordfinder();
string word;
string engSent;
int x;
int main()
{
cout << "Enter a sentence: ";
getline(cin, engSent);
string word = "";
for (x = 0; x < engSent.length(); x++)
{
if (engSent[x] == " " || engSent[x] == "," || engSent[x] == ".")
{
wordfinder();
word = "";
}
}
return 0;
}
void wordfinder()
{
word = engSent.substr(0,engSent[x]);
cout << word;
}

最佳答案

检查字符而不是字符串:

if (engSent[x] == ' ' || engSent[x] == ',' || engSent[x] == '.')

关于c++ - 获取错误 : "ISO C++ forbids comparison between pointer and integer [-fpermissive]" How do I fix?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34844414/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com