为什么我的简单C++“你叫什么名字?”程序不工作?
我一直收到未声明的标识符错误,但我不知道这意味着什么,也不知道如何修复。原谅我,我对这件事还不熟悉为什么我的简单C++“你叫什么名字?”程序不工作?,c++,undeclared-identifier,C++,Undeclared Identifier,我一直收到未声明的标识符错误,但我不知道这意味着什么,也不知道如何修复。原谅我,我对这件事还不熟悉 #include <iostream> #include <string> using namespace std; int main(void); //Not sure why there is a Parse issue? { // insert code here... cout<< "Hello, what is your
#include <iostream>
#include <string>
using namespace std;
int main(void);
//Not sure why there is a Parse issue?
{
// insert code here...
cout<< "Hello, what is your name?";
cin>> Scotty;
cout<< "Hello, "<<Scotty<<endl;
return0;
}
我能够解决之前关于未声明标识符的问题,但现在我得到了一个“预期的非限定id”错误?感谢您回答那些有问题的人,请查看以下内容:
#include <iostream>
using namespace std;
int main() {
string Scotty;
cout << " Hello what is your name";
cin >> Scotty;
cout <<"\nHello"<<Scotty<<endl;
}
您尚未声明名为Scotty的变量。在使用变量之前必须声明变量,因此必须通过添加字符串Scotty进行声明;在打电话给cin之前。您还必须将cin行末尾的运算符>>替换为 您可以在这里复制源代码,您知道Scotty尚未声明为变量我如何声明Scotty为变量?在学习时,您确实应该复习所选语言的基本语法规则。学习谷歌错误消息,以及帮助调试。特别是对于C++,你可以使用CPLUS PLUS作为搜索语句,你需要通过添加语句字符串Scotty来声明Scotty;在cin声明之前。此外,cin>>Scotty>>语法无效,请将该行更改为cin>>Scotty;