C++ 无法使用while运行循环

C++ 无法使用while运行循环,c++,C++,我编写了以下代码: int sum,number; sum=0; number=1; while(number<=11) { sum=sum+number; cout << sum; number++; } cout << "The sum of the fist 11 is" cout << sum; 我无法理解我做错了什么 我放了一个在while循环结束后,但仍然不起作用。将最后一行替换为 cout << "T

我编写了以下代码:

int sum,number;
sum=0;
number=1;

while(number<=11)
{
    sum=sum+number;
    cout << sum;
    number++;
}
cout << "The sum of the fist 11 is" cout << sum;
我无法理解我做错了什么


我放了一个
在while循环结束后,但仍然不起作用。

将最后一行替换为

cout << "The sum of the fist 11 is" << sum;

cout将最后一行替换为

cout << "The sum of the fist 11 is" << sum;
cout更改以下行:

cout << "The sum of the fist 11 is" cout << sum;
cout更改以下行:

cout << "The sum of the fist 11 is" cout << sum;
cout在这里。工作

#include<iostream>
using namespace std;

int main(void)
{
    int sum, number;
    sum=0;
    number=1;

    while(number<=11)
    {
        sum = sum + number;
        cout<<sum<<endl;
        number++;
    }
    cout << "The sum of the fist 11 is "<<sum;
}
#包括
使用名称空间std;
内部主(空)
{
整数和,数字;
总和=0;
数字=1;
虽然(数字在这里它是有效的

#include<iostream>
using namespace std;

int main(void)
{
    int sum, number;
    sum=0;
    number=1;

    while(number<=11)
    {
        sum = sum + number;
        cout<<sum<<endl;
        number++;
    }
    cout << "The sum of the fist 11 is "<<sum;
}
#包括
使用名称空间std;
内部主(空)
{
整数和,数字;
总和=0;
数字=1;

虽然(数字但我如何用字符串表示总和??内容被连接到
cout
,并有效地显示在控制台上。编写相同内容的另一种方法是:
cout为什么要将其拆分为两行?只需从中间删除错误的
cout
。@MikeSeymour这是解决问题的一种方法这样做。我认为我的修复更容易理解发布的错误消息:
expected';'before'cout'
,但我如何用字符串表示和??内容被连接到
cout
,并有效地显示在控制台上。编写相同内容的另一种方法是:
cout Why sp将其分为两行?只需从中间删除错误的
cout
。@MikeSeymour这是一种方法。我认为我的修复更容易理解张贴的错误消息:
预期';“cout”之前的'it't'
@Abdullah it't'不起作用您需要在字符串文字后加一个分号“;”或者将第二个“cout”替换为“发布正确答案。@Abdullah它不起作用,你需要在字符串后面加一个分号”;“或者将第二个“cout”替换为“发布正确答案”。提问者的问题永远是真实的:D,享受提问者的问题永远是真实的:D,享受