输入名称bool不允许.C
type name bool not allowed. c++
有四个错误显示;我不了解它们。
错误1:不允许键入第11行。
错误2:预期a','第11行(Bool(。
错误3:预期a'}'第11行(在true之后(。
错误4:期望声明第12行(在此之前(。
我是新手程序员,我有点想知道自己在做什么。所以请帮忙。这是代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
1 int main{
2 bool alternate = true ;
3 for (int x = 0; x < 8; x++)
4 {
5 for (int y = 0; y < 4; y++)
6 {
7 if (alternate)
8 {
9 cout << "X ";
10 cout << "O ";
11
12 }
13 else
14 {
15 cout << "O ";
16 cout << "X ";
17
18 }
19 }
20 alternate = !alternate;
21
22 cout << endl;
23 }
24 }
main是一个函数,因此您应该将其声明为:
int main() {...
#include" stdafx.h"是Microsoft特定的,并且不会在其他平台上编译。此代码不需要STDAFX.H。
好吧,您只是错过了上述代码中的一些语法。正确的代码是:
#include <iostream>
using namespace std;
int main ()
{
bool alternate = true ;
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 4; y++)
{
if (alternate)
{
cout << "X ";
cout << "O ";
}
else
{
cout << "O ";
cout << "X ";
}
}
alternate = !alternate;
cout << endl;
}
return 0;
}
代码中的错误是您错过了主要方法之后的"(("。另外,您忘了编写返回语句。
相关文章:
- 为什么 Clang 不允许"and"作为函数名称?
- 不允许在向量中添加更多元素
- std::带有自定义缓冲区的 iostream 不允许我写入
- Visual Studio 2017 不允许我创建 C++ 专用模板
- 返回时不允许隐式转换
- 为什么 c++(g++) 不允许模板返回类型和函数名称之间有空格?
- 为什么 c++ 不允许(自动)强制转换?
- 为什么 c++11 不允许使用自动
- 为什么不允许成员函数和非成员函数之间的函数重载?
- 为什么不允许使用可变长度数组作为向量元素?
- 余数除法和不允许除以零 (c++) 时遇到问题
- C++从外部类继承的嵌套类;不允许使用不完整的类型
- 在 c++ 中三元运算符中不允许继续(关键字)吗?
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?
- 错误:在第 6 行'{'标记之前,此处不允许使用函数定义
- 不允许在类定义之外重写
- 不允许运算符 const 参数调用 const 成员函数
- E0322:不允许使用抽象类类型 " " 的对象
- error dllimport 函数的定义不允许在一个特定的联合中,而其他类、结构和联合将按预期导出
- 输入名称bool不允许.C