2014-01-24 88 views
-2

第一次在計算機科學課上。第一個實驗任務。完全寫出了老師寫的東西,但它不會編譯,老師或我都不知道爲什麼。請幫忙。謝謝。錯誤:在';'令牌之前預期的初級表達式

#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:在函數 '詮釋主()':

lab01.cpp:11:錯誤:預期; 'ENDL'

之前 '' lab01.cpp:12:錯誤:預期 ';' 'ENDL' 之前

lab01.cpp:14:錯誤:預期; 'ENDL'

之前 ''

lab01.cpp:19:錯誤:預期 ';' 'ENDL' 之前

lab01.cpp:21:錯誤:預期前主表達式 ';' 令牌

+3

失蹤 「<<」 之前 「ENDL」。 –

+6

如果你的老師在這裏找不到問題,我會很擔心。 –

+0

是的,我們的老師是數學老師,我認爲這是他第一次教csci。 – user3233139

回答

5

之前缺少<<操作者endl構造。更改

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

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

除了缺少<<endl之前(在幾行),你也有線路上的額外的一個:

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

這將導致一旦修復第一個錯誤,您將得到另一個編譯器錯誤。它應該是:

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

cout <<"you stated you live in " << residence <<"."; 
相關問題