【问题标题】:error: expected primary-expression before ‘;’ token [closed]错误:“;”标记之前的预期主表达式[关闭]
【发布时间】:2014-01-24 18:31:26
【问题描述】:

第一次上计算机科学课。第一个实验室任务。写的和老师写的一模一样,但是编译不出来,老师和我都不知道为什么。请帮忙。谢谢。

#include <iostream>
#include <string>

using namespace std;

int main ()
{
int number;
string residence;
//Just an example of a comment
cout << "Hello. Welcome to CSCI-1!" endl;
cout << "Spring 2014" endl;

cout << "please enter a number: " endl;
cin >> number;

cout << "you entered the number: " << number <<endl;

cout<<"Please enter your state of residence: " endl;
cin>>residence;
cout <<"you stated you live in " << residence <<"." <<;
return 0;
}

错误:

lab01.cpp:在函数“int main()”中:

lab01.cpp:11: 错误:在“endl”之前需要“;”

lab01.cpp:12: 错误:在“endl”之前需要“;”

lab01.cpp:14: 错误:在“endl”之前需要“;”

lab01.cpp:19: 错误:在“endl”之前需要“;”

lab01.cpp:21: 错误:';' 标记之前的预期主表达式

【问题讨论】:

  • “endl”前缺少“
  • 如果你的老师看不出这里有什么问题,我真的很担心。
  • 是的,我们的老师是位数学老师,我想这是他第一次教 csci。
  • 你应该向你的大学投诉,因为你指派了一名数学老师来教授他一无所知的科目——几乎任何已经超越初学者状态的人都能立即解释这些错误。

标签: c++ cloud9-ide


【解决方案1】:

您在endl 构造之前缺少&lt;&lt; 运算符。改变

cout << "Hello. Welcome to CSCI-1!" endl;

cout << "Hello. Welcome to CSCI-1!" << endl;

【讨论】:

    【解决方案2】:

    除了endl 之前缺少的&lt;&lt;(在几行中),你还有一个额外的一行:

    cout <<"you stated you live in " << residence <<"." <<;
                                                        ^^ -- extra!
    

    一旦你修复了第一个编译器错误,这将导致你得到另一个编译器错误。应该是:

    cout <<"you stated you live in " << residence <<"." << endl;
    

    cout <<"you stated you live in " << residence <<".";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 2017-09-24
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多