bottomMap 必须在循环开始之前存在
for (int i = 0; i < str.size() ; i++){
if (str[i] != ' ') {
cout << "XXXX";
} else {
if (bottomMap[i] == true) //< ERROR: bootomMap here is not declred.
cout << "YYYY";
else
cout << "X";
}
}
vector <bool> bottomMap(topMap); //< Declared here, but destroyed to the very next '}'
}
尝试这个
vector <bool> bottomMap(topMap); //< MOVED HERE
for (int i = 0; i < str.size() ; i++){
if (str[i] != ' ') {
cout << "XXXX";
} else {
if (bottomMap[i] == true)
cout << "YYYY";
else
cout << "X";
}
}
///< AND NOMORE HERE
}
建议:保持打开和关闭大括号对齐:这将花费更多的行,您将很容易找到事物何时开始和结束它们的存在
这是您的代码,重新对齐:
for (int i = 0; i < str.size() ; i++)
{
if (str[i] != ' ')
{
cout << "XXXX";
}
else
{
if (bottomMap[i] == true) //< ERROR: bottomMap here is not declared.
cout << "YYYY";
else
cout << "X";
}
}
vector <bool> bottomMap(topMap); //< Declared here, but too late!
} //< ERROR: TOO CLOSED BRACES