【问题标题】:Why is my simple C++ "What is your name?" program not working? [duplicate]为什么我的简单 C++ 是“你叫什么名字?”程序不工作? [复制]
【发布时间】:2017-09-10 02:07:08
【问题描述】:

enter image description here

我不断收到“未声明的标识符”错误,但我不知道这意味着什么或如何解决这个问题。请原谅我是新手!

#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”错误?感谢那些回答过的人

【问题讨论】:

  • 你知道的可以复制这里的源代码
  • Scotty 尚未声明为变量
  • 如何将 Scotty 声明为变量?
  • 您确实应该在学习时复习所选语言的基本语法规则。学习谷歌错误消息以及帮助调试。专门针对 c++,您可以使用 cplusplus 作为搜索词
  • 您需要通过在cin 语句之前添加语句string Scotty; 来声明Scotty。此外,cin&gt;&gt;Scotty&gt;&gt; 的语法无效,请将该行更改为 cin&gt;&gt;Scotty;

标签: c++ undeclared-identifier


【解决方案1】:

看看这个:

#include <iostream>

using namespace std;

int main() {

string Scotty;
cout << " Hello what is your name";
cin >> Scotty;

cout <<"\nHello"<<Scotty<<endl;

}

【讨论】:

    【解决方案2】:

    您尚未声明名为 Scotty 的变量。您必须在使用变量之前声明它们,因此您必须在调用 cin 之前通过添加 string Scotty; 来声明。此外,您必须将 cin 行末尾的运算符 &gt;&gt; 替换为 ;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 2019-05-24
      相关资源
      最近更新 更多