gpt4 book ai didi

c++ - 错误 : name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]

转载 作者:太空宇宙 更新时间:2023-11-04 14:38:05 28 4
gpt4 key购买 nike

<分区>

问。编写一个程序,将您不喜欢的单词“哔”掉;也就是说,您使用 cin 读入单词并在 cout 上再次打印它们。如果一个词在你定义的几个词中,你就写出 BLEEP 而不是那个词。 (stroustrup 的 c++ 书)

这是我写的代码:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }
int main()
{
vector<string> disliked;
disliked.push_back("Broccoli");
disliked.push_back("Carrots");
disliked.push_back("Tomatoes");
disliked.push_back("Asparagus");

vector<string> words;
string word;
while (cin >> word) {
words.push_back(word);
}
for (int i = 0; i < words.size(); ++i) {
cout << words[i] << "\t"; //i used it to see if the program was working
}
for (int j = 0; j < disliked.size(); ++j) {
cout << disliked[j] << "\t";
}
for (i = 0; i < j; ++i) {
if (words[i] == disliked[j]) {
cout << "BLEEP";
}
else {
}
}
}

我认为问题是由于我的最终 for 循环引起的,但我不明白要做什么。

这是我得到的错误:

bleep.cpp: In function ‘int main()’:
bleep.cpp:27:8: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
bleep.cpp:27:8: note: (if you use ‘-fpermissive’ G++ will accept your code)
bleep.cpp:27:19: error: name lookup of ‘j’ changed for ISO ‘for’ scoping [-fpermissive]

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