-2

我似乎无法弄清楚为什么它一直说预期的`;' 仅在第 28 行的“keep_window_open”之前请帮忙

#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
inline void keep_window_open(){char ch;cin>>ch;}


int main()

{
cout<<"Please enter your first name(followed by 'enter'):\n";
string first_name;
cin>>first_name;
cout<<"hello,"<<first_name<<"!\n";
keep_window_open();
return 0;
cout<<"please enter last name:\n";
string Last_name;
cin>> Last_name;
cout<<"hello,"<<first_name<<Last_name<<"!\n"
// this is the only keep_window_open() function that gives me the problem 
keep_window_open();
return 0;  
} 
4

2 回答 2

3

在 c++ 中,您的语句应以;

cout<<"hello,"<<first_name<<Last_name<<"!\n"

声明应该以;

cout<<"hello,"<<first_name<<Last_name<<"!\n";

这是需要终止的语句列表

Statement type        Termination required?
==============        =====================
labelled statement              N (a)
expression                      Y
compound statements             N (a)
selection statements            N (a)
iteration statements            N (a) (b)
jump statements                 Y
declaration statement           Y

(a) 虽然有时看起来这些以分号结尾,但事实并非如此。该声明:

if (i == 1) doSomething(); 有分号终止内部表达式语句,而不是复合语句,当您检查上面的第一个代码段时,这应该是显而易见的,它包含在 {} 大括号中。

(b) do 需要 while 表达式后面的分号。

于 2013-09-03T07:34:40.903 回答
0

因为您之前忘记了;在线(最后cout没有 a;的 ):

改变:

cout<<"hello,"<<first_name<<Last_name<<"!\n"

到:

cout<<"hello,"<<first_name<<Last_name<<"!\n";

...看看事情是否会变得更好。

于 2013-09-03T07:30:32.047 回答