C++ |语法错误:标识符“i”
嘿伙计们,我很确定其他人也遇到过这个问题,但我只是找不到任何相关的问题。这也可能是一些非常愚蠢的事情,比如打字错误或其他什么,但我无法弄清楚>。<
代码有什么问题,我总是收到此错误:
错误 C2061:语法错误:标识符 'i'
#include <iostream>
#include <string>
using namespace std;
class MahinLuokka {
public:
void setNum(int);
int getNum();
private:
int mahi_num;
};
int main()
{
int i;
do {
cout << "Insert number between 1-100" << endl;
cin >> i;
} while i > 100 || i < 0;
MahinLuokka mahi;
mahi.setNum(i);
cout << mahi.getNum() << endl;
mahi.setNum(5);
cout << "mahi_num set to 5" << endl;
cout << mahi.getNum() << endl;
// end
int x;
cin >> x;
return 0;
}
void MahinLuokka::setNum(int number)
{
mahi_num = number;
}
int MahinLuokka::getNum()
{
return mahi_num;
}
Hey guys, I'm pretty sure someone else has had this problem too, but I just couldn't find any related problems. This is also probably something really stupid like a typo or something, but I'm not able to figure it out >.<
What's wrong with the code, I always get this error:
error C2061: syntax error : identifier 'i'
#include <iostream>
#include <string>
using namespace std;
class MahinLuokka {
public:
void setNum(int);
int getNum();
private:
int mahi_num;
};
int main()
{
int i;
do {
cout << "Insert number between 1-100" << endl;
cin >> i;
} while i > 100 || i < 0;
MahinLuokka mahi;
mahi.setNum(i);
cout << mahi.getNum() << endl;
mahi.setNum(5);
cout << "mahi_num set to 5" << endl;
cout << mahi.getNum() << endl;
// end
int x;
cin >> x;
return 0;
}
void MahinLuokka::setNum(int number)
{
mahi_num = number;
}
int MahinLuokka::getNum()
{
return mahi_num;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将条件括在括号中。换句话说,将其更改
为:
You need to enclose the conditions in parentheses. In other words, change this:
To this:
while
需要一个(
,所以应该是while (i > 100 || i < 0);
while
requires a(
, so it should bewhile (i > 100 || i < 0);