C++ 无法在for循环中打印

C++ 无法在for循环中打印,c++,c++14,C++,C++14,下面是我的代码: 包括 使用名称空间std; int main { int numoftimes,n,sumvalue=0,strvalue=0; 不能>多次; 对于n=1;n您需要打印循环中的每个迭代: for (n = 1; n <= numboftimes; n++) { sumvalue += n; strvalue += 1; cout << "This is the " << numboftimes << " iter

下面是我的代码:

包括 使用名称空间std; int main { int numoftimes,n,sumvalue=0,strvalue=0; 不能>多次;
对于n=1;n您需要打印循环中的每个迭代:

for (n = 1; n <= numboftimes; n++) {
    sumvalue += n;
    strvalue += 1;
    cout << "This is the " << numboftimes << " iteration to print" << endl;
    cout << "The sum is " << sumvalue << endl;
}

通过这种方式,您可以打印每个迭代。

当您打印变量numoftimes时,您只是打印一个常量值

for(int n=0; n < numboftimes ; n++)
     cout << n << endl;

无论如何,你把cout放在for循环之外,该循环只输出一次,并且只输出整数numb次

为什么不呢?当你尝试时会发生什么?请阅读,然后回答你的问题,并添加打印在循环中的代码。是的,很抱歉,因为我是在手机上写的。