编译器指出结构和 int 说明的错误 2059
Compiler stating error 2059 for struct and int description
我(可能显然(很新,正在尝试为我的第一个项目构建一个计算器。我想测试我的第一个概念,但在编译时,我的 InterFace 结构的末端大括号以及我的 int AddUp 的第一个大括号出现 2059 错误。这些似乎是完全随机的错误。如果有帮助,错误是针对行 (10,1( 和 (16,2(,尽管我怀疑 1 和 2 是指记录的类似错误的数量?任何帮助将不胜感激。
1 #include <iostream>
2
3 struct InterFace
4 {
5 char Buttons[4][4]
6 {
7 Buttons[1] = "u00B1";
8 std::cout << Buttons[1] << std::endl;
9 }
10 };
11
12
13 struct Addition
14 {
15 int AddUp[2]
16 {
17
18 }
19 };
int main()
{
std::cin.get();
}
您没有正确的核心概念,在编写这样的程序之前,您可能应该完成一些C++教程或课程。
几件事:
- ±符号是 unicode 字符。
char
in C++ 表示单个字节,如果引用文本数据,则通常是 ASCII 值。所以它不能存储 unicode +- 符号。相反,您可以将此 unicode 值存储在std::string buttons[4][4];
中(尽管完整的答案要复杂得多(。 - 在C++中,
'a'
指的是字符a,但"a"
指的是const char*
。如果不是因为 unicode 问题,你应该使用单引号。 - 您尝试分配给
Buttons[1]
,但按钮是一个二维数组。元素 1 还引用数组的第二个元素,这可能不是您想要的。相反,你可以写Buttons[0][0]='a';
- 您没有成员函数/成员变量的概念。执行此操作的正确方法是拥有一个初始值设定项函数,然后调用它。
这是一个固定/工作示例,但我真的建议先浏览其他教程!
#include <iostream>
#include <string>
struct Interface {
std::string buttons[4][4];
void initialize_interface() {
buttons[0][0] = std::string("u00B1");
std::cout << buttons[0][0] << std::endl;
}
};
int main() {
Interface my_interface;
my_interface.initialize_interface();
return 0;
}
正如M.M.在评论中指出的那样,更具范范性的方法如下:
#include #include
struct Interface {
std::string buttons[4][4];
Interface() {
buttons[0][0] = std::string("u00B1");
std::cout << buttons[0][0] << std::endl;
}
};
int main() {
Interface my_interface;
return 0;
}
Interface::Interface
称为构造函数,它在初始化时运行。
由于我无法按照最初的意图构建计算器,所以我走了一条不同的路线。我用开关完成了一个基本的。
#include <iostream>
int main()
{
int r;
int a;
int b;
int result1;
int result2;
int result3;
int result4;
int result5;
std::cout << "Please choose from the available options:" << std::endl << "0. Add" << std::endl << "1. Subtract" << std::endl << "2. Multiply" << std::endl << "3. Divide" << std::endl << "4. Modulo" << std::endl;
std::cin >> r;
switch (r % 5)
{
case 0:
std::cout << "You have chosen to Add, please enter two digits" << std::endl;
std::cin >> a;
std::cin >> b;
result1 = a + b;
std::cout << "Your sum is " << result1 << std::endl;
break;
case 1:
std::cout << "You have chosen to Subtract, please enter two digits" << std::endl;
std::cin >> a;
std::cin >> b;
result2 = a - b;
std::cout << "Your difference is " << result2 << std::endl;
break;
case 2:
std::cout << "You have chosen to Multiply, please enter two digits" << std::endl;
std::cin >> a;
std::cin >> b;
result3 = a * b;
std::cout << "Your product is " << result3 << std::endl;
break;
case 3:
std::cout << "You have chosen to Divide, please enter two digits" << std::endl;
std::cin >> a;
std::cin >> b;
result4 = a / b;
std::cout << "Your quotient is " << result4 << std::endl;
break;
case 4:
std::cout << "You have chosen to perform Modulus, please enter two digits" << std::endl;
std::cin >> a;
std::cin >> b;
result5 = a % b;
std::cout << "Your answer is " << result5 << std::endl;
break;
}
std::cin.get();
std::cin.get();
}
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- 编译器指出结构和 int 说明的错误 2059
- 有关使用标志位设置内部错误标志的说明
- 当强调CPP明确说明一个弹性时,我会出现错误
- 我该如何解决错误,说明创建图形对象没有放置在图形场景中
- 严重性代码说明项目文件行抑制状态错误 C2676 二进制">>":"std::ifstream"
- ADTF 无结构类型"错误的媒体说明
- 在Ubuntu 14.04启动我的应用程序时,非法说明(核心转储)错误,如何查看转储
- 记忆错误结果的说明[编译器行为]
- 如何使错误日志更详细地说明对的未定义引用
- 奇怪的编译器错误,说明我的迭代器未定义